Skip to content

Commit 857166c

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #79839
2 parents 4903f7c + 0c28b47 commit 857166c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

ext/standard/array.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,16 @@ static int php_array_walk(zval *array, zval *userdata, int recursive) /* {{{ */
13911391
zend_hash_move_forward_ex(target_hash, &pos);
13921392
continue;
13931393
}
1394+
1395+
/* Add type source for property references. */
1396+
if (Z_TYPE_P(zv) != IS_REFERENCE && Z_TYPE_P(array) == IS_OBJECT) {
1397+
zend_property_info *prop_info =
1398+
zend_get_typed_property_info_for_slot(Z_OBJ_P(array), zv);
1399+
if (prop_info) {
1400+
ZVAL_NEW_REF(zv, zv);
1401+
ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(zv), prop_info);
1402+
}
1403+
}
13941404
}
13951405

13961406
/* Ensure the value is a reference. Otherwise the location of the value may be freed. */
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug #79839: array_walk() does not respect property types
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public int $prop = 42;
8+
}
9+
10+
$test = new Test;
11+
try {
12+
array_walk($test, function(&$ref) {
13+
$ref = []; // Should throw
14+
});
15+
} catch (TypeError $e) {
16+
echo $e->getMessage(), "\n";
17+
}
18+
var_dump($test);
19+
20+
?>
21+
--EXPECT--
22+
Cannot assign array to reference held by property Test::$prop of type int
23+
object(Test)#1 (1) {
24+
["prop"]=>
25+
&int(42)
26+
}

0 commit comments

Comments
 (0)