3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<root><case1><name> </name></case1><case2><name></name></case2><case3><name>ukits</name></case3></root>'; libxml_use_internal_errors(true); $content = simplexml_load_string($xml); if ($content === false) { libxml_clear_errors(); } print_r($content); $content = objectToArray($content); print_r($content); function objectToArray($obj) { if (is_object($obj)) { $obj = (array) $obj; } if (count($obj) == 0) { $obj = ''; } if (is_array($obj)) { $new = array(); foreach ($obj as $key => $val) { $new[$key] = objectToArray($val); } } else { $new = $obj; } return $new; }
Output for git.master, git.master_jit, rfc.property-hooks
SimpleXMLElement Object ( [case1] => SimpleXMLElement Object ( [name] => SimpleXMLElement Object ( ) ) [case2] => SimpleXMLElement Object ( [name] => SimpleXMLElement Object ( ) ) [case3] => SimpleXMLElement Object ( [name] => ukits ) ) Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in /in/SvI3B:21 Stack trace: #0 /in/SvI3B(26): objectToArray('ukits') #1 /in/SvI3B(26): objectToArray(Array) #2 /in/SvI3B(14): objectToArray(Array) #3 {main} thrown in /in/SvI3B on line 21
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
52.38 ms | 402 KiB | 8 Q