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
Hey Nikita,
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.)
The abbreviation seems rather pointless, I’d rather string over str.
I’d suggest this convention:
- Use “string” or omit the suffix for zend_string
- Use “cstring” for C strings (char*)
- Don’t use “str”
That sound good?
Andrea Faulds
http://ajf.me/
Or maybe be more explicit and use "cstr" for C strings. (For symmetry the
zend_string type could become zstr.)
I personally prefer cstr/zstr for explicitness, but agree that the
main focus should be consistency.
-Sara
And yes, the fact that smart_string deals with char* while smart_str
deals with zstring, but smart_str used to be the char* API. That's a
big bucket of clown.
Or maybe be more explicit and use "cstr" for C strings. (For symmetry the
zend_string type could become zstr.)I personally prefer cstr/zstr for explicitness, but agree that the
main focus should be consistency.-Sara
And yes, the fact that smart_string deals with char* while smart_str
deals with zstring, but smart_str used to be the char* API. That's a
big bucket of clown.
I favor 'zstr' and 'cstr' over something like 'str' and 'string'.
Perhaps zend_zstr_ would seem a bit redundant (zend zend string) but
better than ambiguity and having to look it up.
Or maybe be more explicit and use "cstr" for C strings. (For symmetry the
zend_string type could become zstr.)I personally prefer cstr/zstr for explicitness, but agree that the
main focus should be consistency.
Yep I like explicitness as well, but I would be OK with str/cstr as well
Is the smart_str dealing with zend_string in PHP7 a naming joke or ?
This should obviously be fixed as well
Julien