SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    63
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what is binary safe?

    What does it mean when someone says that a PHP function is binary safe?

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In C (and other machine-level languages), strings are often represented internally by a pointer to a memory segment that contains the data. The way that a string is terminated, is by a special marker (a byte-value of 0 aka. the null byte). This means that such strings can not contain the value 0, since it would end the string. This works because most charsets doesn't use the first couple of bytes to represent characters, but it won't work if you try to store something other than strings. Another way of storing strings would be a pointer + an integer that holds the length of the string. With this approach, the contents of the string doesn't matter, so it can hold a 0 byte. It makes the management of the string more complicated though, since you have to pass two values (pointer+length), instead of just one.

    So, generally speaking, a binary-safe function is one where the contents of the string doesn't matter.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •