Search code examples
phpstringstandardsphp-internals

PHP string length


PHP coding standards say:

... PHP holds the length property of each string, and that it shouldn't be calculated with strlen(). Write your functions in a such a way so that they'll take advantage of the length property, both for efficiency and in order for them to be binary-safe. ...

How can I access this length property? Or do I misunderstand it?


Solution

  • As Ignacio mentioned in another post:

    They're talking about the C function, not the PHP function. The C function will stop counting after the first \0, but PHP strings can contain \0 elsewhere other than the end.

    That document is most likely about how to extend PHP's engine, rather than programming in PHP itself.