/* Go through the input array */
zend_hash_internal_pointer_reset(Z_ARRVAL_P(input));
while(zend_hash_get_current_data(Z_ARRVAL_P(input), (void **)&entry) == SUCCESS) {
- zval subject;
+ zval subject = **entry;
- subject = **entry;
if (Z_TYPE_PP(entry) != IS_STRING) {
zval_copy_ctor(&subject);
convert_to_string_with_converter(&subject, UG(utf8_conv));
}
/* If the entry fits our requirements */
- if ((count > 0 && !invert) ||
- (count == PCRE_ERROR_NOMATCH && invert)) {
+ if ((count > 0 && !invert) || (count == PCRE_ERROR_NOMATCH && invert)) {
+
Z_ADDREF_PP(entry);
/* Add to return array */
--- /dev/null
+--TEST--
+Bug #44925 (preg_grep() modifies input array)
+--FILE--
+<?php
+$str1 = 'a';
+$str2 = 'b';
+
+$array=Array("1",2,3,1.1,FALSE,NULL,Array(), $str1, &$str2);
+
+var_dump($array);
+
+var_dump(preg_grep('/do not match/',$array));
+
+$a = preg_grep('/./',$array);
+var_dump($a);
+
+$str1 = 'x';
+$str2 = 'y';
+
+var_dump($a); // check if array is still ok
+
+var_dump($array);
+
+?>
+--EXPECTF--
+array(9) {
+ [0]=>
+ unicode(1) "1"
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ [3]=>
+ float(1.1)
+ [4]=>
+ bool(false)
+ [5]=>
+ NULL
+ [6]=>
+ array(0) {
+ }
+ [7]=>
+ unicode(1) "a"
+ [8]=>
+ &unicode(1) "b"
+}
+
+Notice: Array to string conversion in %sbug44925.php on line 9
+array(0) {
+}
+
+Notice: Array to string conversion in %sbug44925.php on line 11
+array(7) {
+ [0]=>
+ unicode(1) "1"
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ [3]=>
+ float(1.1)
+ [6]=>
+ array(0) {
+ }
+ [7]=>
+ unicode(1) "a"
+ [8]=>
+ &unicode(1) "b"
+}
+array(7) {
+ [0]=>
+ unicode(1) "1"
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ [3]=>
+ float(1.1)
+ [6]=>
+ array(0) {
+ }
+ [7]=>
+ unicode(1) "a"
+ [8]=>
+ &unicode(1) "y"
+}
+array(9) {
+ [0]=>
+ unicode(1) "1"
+ [1]=>
+ int(2)
+ [2]=>
+ int(3)
+ [3]=>
+ float(1.1)
+ [4]=>
+ bool(false)
+ [5]=>
+ NULL
+ [6]=>
+ array(0) {
+ }
+ [7]=>
+ unicode(1) "a"
+ [8]=>
+ &unicode(1) "y"
+}