3v4l.org

run code in 300+ PHP versions simultaneously
<?php $config = ['legendaryName' => 'legendary_name']; $data = ['legendary_name' => 'The Hammer']; class Warrior { use DbHydrate; private $legendaryName; } trait DbHydrate { public function hydrate($config, $data) { foreach($config as $attributeName => $column) { var_dump(property_exists($this,$attributeName)); $this->{$attributeName} = $data[$column]; } } } $legendaryWarrior = new Warrior; $legendaryWarrior->hydrate($config, $data); var_dump($legendaryWarrior); $config = ['classicalName' => 'classical_name']; $data = ['classical_name' => 'John']; $testWarrior = new Warrior; $testWarrior->hydrate($config, $data); var_dump($testWarrior);
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
bool(true) object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" } bool(false) Deprecated: Creation of dynamic property Warrior::$classicalName is deprecated in /in/DI57T on line 19 object(Warrior)#2 (2) { ["legendaryName":"Warrior":private]=> NULL ["classicalName"]=> string(4) "John" }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 bool(true) object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" } bool(false) Deprecated: Creation of dynamic property Warrior::$classicalName is deprecated in /in/DI57T on line 19 object(Warrior)#2 (2) { ["legendaryName":"Warrior":private]=> NULL ["classicalName"]=> string(4) "John" }
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
bool(true) object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" } bool(false) object(Warrior)#2 (2) { ["legendaryName":"Warrior":private]=> NULL ["classicalName"]=> string(4) "John" }

preferences:
162.23 ms | 403 KiB | 188 Q