3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.21
Fatal error: Call to undefined function isArrayAssociative() in /in/FPHKM on line 8
Process exited with code 255.

preferences:
185.68 ms | 402 KiB | 242 Q