1.2.74. Avoid get_object_vars()¶
get_object_vars() changes behavior between PHP 7.3 and 7.4.
Calling get_object_vars() on an ArrayObject <https://www.php.net/manual/en/class.`arrayobject.php>`_ instance will now always return the properties of the ArrayObject <https://www.php.net/manual/en/class.`arrayobject.php>`_ itself (or a subclass). Previously it returned the values of the wrapped array/object unless the ArrayObject::STD_PROP_LIST flag was specified.
It also behaves different within and outside a class.
<?php
// Illustration courtesy of Doug Bierer
$obj = new ArrayObject(['A' => 1,'B' => 2,'C' => 3]);
var_dump($obj->getArrayCopy());
var_dump(get_object_vars($obj));
?>
See also get_object_vars script on 3V4L, The Strange Case of ArrayObject and Standard PHP Library (SPL).
1.2.74.1. Connex PHP features¶
1.2.74.1.1. Suggestions¶
Use ArrayObject and getArrayCopy() method
1.2.74.1.2. Specs¶
Short name |
Php/AvoidGetobjectVars |
Rulesets |
All, Changed Behavior, CompatibilityPHP74, CompatibilityPHP80 |
Exakat since |
2.2.1 |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Changed Behavior |
PHP 7.4 |
Precision |
High |
Available in |