3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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) { $attribute = $this->{$attributeName}; var_dump(isset($attribute)); $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);
based on ESvKA
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.21.3, 7.0.0 - 7.3.0beta1
bool(false) object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" } Notice: Undefined property: Warrior::$classicalName in /in/LYKT0 on line 17 bool(false) object(Warrior)#2 (2) { ["legendaryName":"Warrior":private]=> NULL ["classicalName"]=> string(4) "John" }
Output for hhvm-3.22.0
bool(false) object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" } Notice: Undefined property: Warrior::$classicalName in /in/LYKT0 on line -1 bool(false) object(Warrior)#2 (2) { ["legendaryName":"Warrior":private]=> NULL ["classicalName"]=> string(4) "John" }