3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class ObjContainer { } class Array2Obj { public function isArrayAssociative(array $array) { return (bool) count(array_filter(array_keys($array), 'is_string')); } public function __CONSTRUCT(array $array) { if(isArrayAssociative($array)) { $obj = new ObjContainer; foreach($array as $key => $val) { if(is_array($val)) { $obj->{$key} = new Array2Obj($val); } else { $obj->{$key} = $val; } } return $obj; } else { $array = array(); foreach($array as $val) { if(is_array($val)) { $array[] = new Array2Obj($val); } else { $array[] = $val; } } return $array; } } } $array = ["database"=>["host"=>"localhost","dbname"=>"mydb","user"=>"root","password"=>""]]; $xml = new Array2Obj($array);
based on 4R3Q5
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to undefined function isArrayAssociative() in /in/FPHKM:8 Stack trace: #0 /in/FPHKM(35): Array2Obj->__CONSTRUCT(Array) #1 {main} thrown in /in/FPHKM on line 8
Process exited with code 255.
Output for 5.4.0 - 5.6.21
Fatal error: Call to undefined function isArrayAssociative() in /in/FPHKM on line 8
Process exited with code 255.
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/FPHKM on line 34
Process exited with code 255.