/* Go through the input array */
zend_hash_internal_pointer_reset(Z_ARRVAL_P(input));
while ((entry = zend_hash_get_current_data(Z_ARRVAL_P(input))) != NULL) {
- zval subject;
+ zval subject, *ref_entry = NULL;
if (Z_TYPE_P(entry) == IS_REFERENCE) {
+ ref_entry = entry;
entry = Z_REFVAL_P(entry);
}
/* If the entry fits our requirements */
if ((count > 0 && !invert) || (count == PCRE_ERROR_NOMATCH && invert)) {
- if (Z_REFCOUNTED_P(entry)) Z_ADDREF_P(entry);
+ if (ref_entry) {
+ Z_ADDREF_P(ref_entry);
+ entry = ref_entry;
+ } else if (Z_REFCOUNTED_P(entry)) {
+ Z_ADDREF_P(entry);
+ }
/* Add to return array */
switch (zend_hash_get_current_key_ex(Z_ARRVAL_P(input), &string_key, &num_key, 0, NULL))