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) { if(property_exists($this, $attributeName)) { $this->{$attributeName} = $data[$column]; } else { throw new \Exception(sprintf('The property %s does not exists in %s', $attributeName, self::class)); } } } } $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 7.0.0 - 7.0.33, 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, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" } Fatal error: Uncaught Exception: The property classicalName does not exists in Warrior in /in/s4eIY:21 Stack trace: #0 /in/s4eIY(36): Warrior->hydrate(Array, Array) #1 {main} thrown in /in/s4eIY on line 21
Process exited with code 255.
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 object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" } Fatal error: Uncaught Exception: The property classicalName does not exists in Warrior in /in/s4eIY:21 Stack trace: #0 /in/s4eIY(36): Warrior->hydrate(Array, Array) #1 {main} thrown in /in/s4eIY on line 21
Process exited with code 255.
Output for 5.6.5 - 5.6.40
object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" } Fatal error: Uncaught exception 'Exception' with message 'The property classicalName does not exists in Warrior' in /in/s4eIY:21 Stack trace: #0 /in/s4eIY(36): Warrior->hydrate(Array, Array) #1 {main} thrown in /in/s4eIY on line 21
Process exited with code 255.
Output for 5.6.0 - 5.6.4
object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" } Fatal error: Uncaught exception 'Exception' with message 'The property classicalName does not exists in DbHydrate' in /in/s4eIY:21 Stack trace: #0 /in/s4eIY(36): Warrior->hydrate(Array, Array) #1 {main} thrown in /in/s4eIY on line 21
Process exited with code 255.

preferences:
215.67 ms | 401 KiB | 286 Q