Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-1073

Remove superfluous php_array_exists calls where possible

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.7.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      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 ... }
      

            Assignee:
            andreas.braun@mongodb.com Andreas Braun
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: