-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
We can rely on some php_array_fetch functions to return NULL if a key doesn't exist, rather than call php_array_exists first. Note that some fetch functions return default values (e.g. bool fetching), so we still might need php_array_exists there is an unset value must be distinguished.
Quoting a chat with sgolemon:
jmikola: php_array_exists isn't really needed if we're using php_array_fetch and are comfortable checking for a NULL zval * return value, correct? just curious as fetch seems to use zend_symtable_str_find while exists uses zend_symtable_str_exists. it looks like zend_symtable_str_find would return null if the symtable entry doesn't exist but i'm not 100% sure
sgolemon: Your assumption is correct. The _exists() variants are largely an artifact of PHP4/5's variable and array API. Then we changed to the more more sane API in PHP 7, those APIs got converted over purely to make converstion from older extensions more straight forward. So you’ll see a lot of idioms in extensions that were translated by someone with a reasonable amount of clue looking something like this:if ((zval *thing = zend_symtable_find(ht, zstr))) { .. use thing ... } else { ... i haz no thing ... }
- is related to
-
PHPC-1057 Refactor option parsing for execute methods
- Closed