note 992 deleted from function.fputs by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 12:19:02 +0000 |
| Subject: | note 992 deleted from function.fputs by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197178@lists.php.net to get a copy of this message | ||
Note Submitter: adam at nedstat dot nl
----
A note about including length: if you are writing binary data you should *always* specify the
data's length. The reason is that the operating system has a special character to denote end
of *strings*, but not for binary data. Binary data can be anything, so you can't very well
reserve an end-of-data character. So the reason why writing binary data without specifying
it's length can truncate it is that the only thing the system has to go on (without writing the
entire contents of memory starting at the variable's address) is the end-of-string character,
which could very well appear randomly in the middle of your set of binary data. The reason that
length() could have worked on the variable is that it is implemented in C as sizeof(), which
actually fetches the size of the memory chunk associated with the variable, but this is not
advisable because sizeof() can also return the size of the *pointer* to the variable if you're
not careful (ie, passing it by reference into a second function). In C it's best to keep track
of size of the data you are accumulating as you accumlate it, so probably in PHP, too.