[php-src] master: std: loop through parent entries prior to setting the return value (#24309)

From: Date: Wed, 14 Oct 2026 11:42:30 +0000
Subject: [php-src] master: std: loop through parent entries prior to setting the return value (#24309)
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142246@lists.php.net to get a copy of this message
Author: Gina Peter Banyard (Girgias) Committer: GitHub (web-flow) Pusher: Girgias Date: 2026-10-14T12:42:26+01:00 Commit: https://github.com/php/php-src/commit/9e0e6062a4ef4da8f5e35c0e4877eb98a6cb7944 Raw diff: https://github.com/php/php-src/commit/9e0e6062a4ef4da8f5e35c0e4877eb98a6cb7944.diff std: loop through parent entries prior to setting the return value (#24309) Rather than fetching the HashTable once again after. Changed paths: M ext/standard/browscap.c Diff: diff --git a/ext/standard/browscap.c b/ext/standard/browscap.c index 7534615a946b..016b09e9c109 100644 --- a/ext/standard/browscap.c +++ b/ext/standard/browscap.c @@ -700,7 +700,6 @@ PHP_FUNCTION(get_browser) bool return_array = 0; browser_data *bdata; browscap_entry *found_entry = NULL; - HashTable *agent_ht; ZEND_PARSE_PARAMETERS_START(0, 2) Z_PARAM_OPTIONAL @@ -783,15 +782,7 @@ PHP_FUNCTION(get_browser) zend_string_release_ex(lookup_browser_name, false); - agent_ht = browscap_entry_to_array(bdata, found_entry); - - if (return_array) { - RETVAL_ARR(agent_ht); - } else { - object_and_properties_init(return_value, zend_standard_class_def, agent_ht); - } - - HashTable *target_ht = return_array ? Z_ARRVAL_P(return_value) : Z_OBJPROP_P(return_value); + HashTable *agent_ht = browscap_entry_to_array(bdata, found_entry); while (found_entry->parent) { found_entry = zend_hash_find_ptr(bdata->htab, found_entry->parent); @@ -799,7 +790,13 @@ PHP_FUNCTION(get_browser) break; } - browscap_entry_add_kv_to_existing_array(bdata, found_entry, target_ht); + browscap_entry_add_kv_to_existing_array(bdata, found_entry, agent_ht); + } + + if (return_array) { + RETVAL_ARR(agent_ht); + } else { + object_and_properties_init(return_value, zend_standard_class_def, agent_ht); } } /* }}} */

« previous php.cvs (#142246) next »