|  | Posted by Taras_96 on 01/23/07 12:46 
Hi everyone,
 I'm lost as to the meaning of a function being 'binary-safe'. The
 Wikipedia entry states that:
 
 "essentially one that treats its input as a raw stream of data without
 any specific format" and that
 
 "Most functions using any special or markup characters, such as escape
 codes or those that expect null-terminated strings are not binary
 safe".
 
 This to me implies that the function need not know what the bytes
 represent, it operates on the data as a raw byte stream. If this is the
 case, I can't see how strpos would be binary-safe (it is documented as
 such). For example, by calling 'strpos('a','cat')', surely the function
 itself must know that the strings 'a' and 'cat' are null terminated,
 and thus according to the wikipedia definition (since special
 significance is given to the null character) the function is not binary
 safe. To further illustrate my point, what would happen if the strings
 that were passed in were encoded in UCS-2, where the string 'a' would
 be encoded as '00 61' (assuming big endian encoding) - wouldn't strpos
 recognise the '00' byte as an ASCII null character, and conclude that
 the first parameter was simply an empty string?
 
 This post:
 http://groups.google.com/group/php.general/browse_thread/thread/c401d89a4a68e94b/e7820fe40145ac7b?lnk=st&q=what+is+%22binary+safe%22&rnum=4&hl=en#e7820fe40145ac7b
 offers a different definition, which doesn't make much sense to me.
 
 To add to the confusion, other websites suggest that 'binary-safe'
 simply implies that the function can operate on the given data without
 altering it.
 
 What exactly is binary-safe in the PHP context? Could examples of
 binary-safe and non binary-safe functions be given?
 
 Thanks
 
 Taras
  Navigation: [Reply to this message] |