3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $bar1 = 'a'; private $bar2 = 'b'; public function Update($updateInfo) { $this->$updateInfo['property'] = $updateInfo[$updateInfo['property']]; } } $objFoo = new Foo(); $updateInfo['bar1'] = 'newVal'; $updateInfo['property'] = 'bar1'; $objFoo->Update($updateInfo); var_dump($objFoo);
Output for 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
Warning: Array to string conversion in /in/sI3AE on line 9 Deprecated: Creation of dynamic property Foo::$Array is deprecated in /in/sI3AE on line 9 object(Foo)#1 (3) { ["bar1":"Foo":private]=> string(1) "a" ["bar2":"Foo":private]=> string(1) "b" ["Array"]=> array(1) { ["property"]=> string(6) "newVal" } }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33
Warning: Array to string conversion in /in/sI3AE on line 9 object(Foo)#1 (3) { ["bar1":"Foo":private]=> string(1) "a" ["bar2":"Foo":private]=> string(1) "b" ["Array"]=> array(1) { ["property"]=> string(6) "newVal" } }
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
Notice: Array to string conversion in /in/sI3AE on line 9 object(Foo)#1 (3) { ["bar1":"Foo":private]=> string(1) "a" ["bar2":"Foo":private]=> string(1) "b" ["Array"]=> array(1) { ["property"]=> string(6) "newVal" } }
Output for 7.3.32 - 7.3.33
object(Foo)#1 (3) { ["bar1":"Foo":private]=> string(1) "a" ["bar2":"Foo":private]=> string(1) "b" ["Array"]=> array(1) { ["property"]=> string(6) "newVal" } }

preferences:
82.51 ms | 410 KiB | 5 Q