Passing An Object To array_walk() Is Deprecated
array_walk() and array_walk_recursive() have always accepted an object as their first argument, walking its accessible public properties as if they were an array. Until PHP 8.6, this worked silently. In PHP 8.6, passing an object to either function emits a deprecation notice suggesting get_object_vars() first, even though the walk itself still happens and mutates the object’s properties exactly as before.
PHP code
<?php
class Point {
public $x = 1;
public $y = 2;
}
$p = new Point();
array_walk($p, function (&$value, $key) {
$value = $value * 10;
});
var_dump($p);
?>
Before
object(Point)#1 (2) {
["x"]=>
int(10)
["y"]=>
int(20)
}
After
PHP Deprecated: array_walk(): Passing an object for argument #1 $array to array_walk() is deprecated, call get_object_vars() first instead
Deprecated: array_walk(): Passing an object for argument #1 $array to array_walk() is deprecated, call get_object_vars() first instead
object(Point)#1 (2) {
["x"]=>
int(10)
["y"]=>
int(20)
}
PHP version change
This behavior was deprecated in 8.6.
This behavior changed in .