PHP 7 API naming conventions: str vs string
| From: | Nikita Popov | Date: | Sat, 03 Jan 2015 23:42:44 +0000 |
| Subject: | PHP 7 API naming conventions: str vs string | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-80129@lists.php.net to get a copy of this message | ||
Hi internals!
PHP 7 uses two different string types. One is the ordinary C string char*,
the other is a custom zend_string* structure, which additionally embeds
length and GC info.
We currently have a bunch of APIs that accept either C strings or
zend_strings, but the naming is pretty much random wrt str/string usage.
Examples:
* The main zend_string API is prefixed with zend_string_
* The smart string API for zend_strings uses the name smart_str, whereas
the smart string API for C strings uses smart_string. To add insult to
injury in PHP 5 smart_str was the one for C strings.
* The hash API uses _str to denote APIs that accept C strings instead of
zend_strings
* ZVAL_STR is used for zend_strings, while ZVAL_STRING is for C strings
* zend_str_tolower works on C strings, whereas zend_string_tolower is for
zend_strings
* ... many more
Basically if you have two APIs, one using str, the other using string, you
can't tell which one is for C strings and which one is for zend_strings. It
could be either way.
It would be nice to have a convention for this and stick with it. E.g.
"string" is for zend_strings and "str" for C strings.
Or maybe be more explicit and use "cstr" for C strings. (For symmetry the
zend_string type could become zstr.)
Thanks,
Nikita