3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class XML { public function __CONSTRUCT($array) { foreach($array as $key => $val) { if(isset($key) && $key) { $this->$key = (object) null; $this->$val = $val->bindTo($this->$key); } else { $this->$val = (object) null; $this->$val = $val->bindTo($this->$val, $this->$val); } } } } $array = ["database"=>["host"=>"localhost","dbname"=>"mydb","user"=>"root","password"=>""]]; $xml = new XML($array); echo($xml->{"database"}->{"host"});
based on 4Xpub
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to a member function bindTo() on array in /in/Ue0Os:7 Stack trace: #0 /in/Ue0Os(17): XML->__CONSTRUCT(Array) #1 {main} thrown in /in/Ue0Os on line 7
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Fatal error: Call to a member function bindTo() on array in /in/Ue0Os on line 7
Process exited with code 255.
Output for 5.4.0 - 5.5.35
Fatal error: Call to a member function bindTo() on a non-object in /in/Ue0Os on line 7
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Ue0Os on line 16
Process exited with code 255.