Passing Objects Is Deprecated¶
Several array functions, such as current, next, prev, reset used to accept both objects and arrays. Since PHP 8.0, they only work on arrays.
each is also part of this modernization, although it was entirely removed in PHP 8.0.
PHP code¶
<?php
$x = (object) ['a' => 1];
var_dump(current($x));
?>
Before¶
int(1)
After¶
PHP Deprecated: current(): Calling current() on an object is deprecated
Deprecated: current(): Calling current() on an object is deprecated
int(1)
PHP version change¶
This behavior changed in 8.1