Question

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?

Was it helpful?

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.

OTHER TIPS

These coding standards are for not intended for web sites developpers using PHP, but for the developpers of the PHP engine itself.

PHP is developped using the C language, and the strlen function to avoid is the C one, not the PHP one.

It's not a "property" in the sense that it would be in other languages (like C#).

You cannot do: myString.Length;

Instead you would need to do: strlen(myString);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top