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 extract($config, $data) { $row = []; foreach($config as $attributeName => $column) { if(property_exists($this, $attributeName)) { $row[$column] = $this->{$attributeName}; } else { throw new \Exception(sprintf('The property %s does not exists in %s', $attributeName, self::class)); } } return $row; } 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->extract($config)); var_dump($legendaryWarrior); /* $config = ['classicalName' => 'classical_name']; $data = ['classical_name' => 'John']; $testWarrior = new Warrior; $testWarrior->hydrate($config, $data); var_dump($testWarrior);*/
based on s4eIY
Output for 7.1.0 - 7.3.0rc3
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Warrior::extract(), 1 passed in /in/IIvtO on line 44 and exactly 2 expected in /in/IIvtO:15 Stack trace: #0 /in/IIvtO(44): Warrior->extract(Array) #1 {main} thrown in /in/IIvtO on line 15
Process exited with code 255.
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.0.27
Warning: Missing argument 2 for Warrior::extract(), called in /in/IIvtO on line 44 and defined in /in/IIvtO on line 15 array(1) { ["legendary_name"]=> string(10) "The Hammer" } object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" }
Output for hhvm-3.22.0
Warning: extract() expects exactly 2 parameters, 1 given in /in/IIvtO on line -1 array(1) { ["legendary_name"]=> string(10) "The Hammer" } object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" }
Output for hhvm-3.18.5 - 3.21.3
Warning: extract() expects exactly 2 parameters, 1 given in /in/IIvtO on line 27 array(1) { ["legendary_name"]=> string(10) "The Hammer" } object(Warrior)#1 (1) { ["legendaryName":"Warrior":private]=> string(10) "The Hammer" }