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) $key; $this->$val = (object) $val; $this->$val = $val->bindTo($this->$key); } else { $this->$val = (object) $val; $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 Ue0Os
Output for 7.0.0 - 7.2.0
Notice: Array to string conversion in /in/4R3Q5 on line 7 Fatal error: Uncaught Error: Call to a member function bindTo() on array in /in/4R3Q5:8 Stack trace: #0 /in/4R3Q5(18): XML->__CONSTRUCT(Array) #1 {main} thrown in /in/4R3Q5 on line 8
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Notice: Array to string conversion in /in/4R3Q5 on line 7 Fatal error: Call to a member function bindTo() on array in /in/4R3Q5 on line 8
Process exited with code 255.
Output for 5.4.0 - 5.5.35
Notice: Array to string conversion in /in/4R3Q5 on line 7 Fatal error: Call to a member function bindTo() on a non-object in /in/4R3Q5 on line 8
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/4R3Q5 on line 17
Process exited with code 255.