3v4l.org

run code in 200+ PHP versions simultaneously
<?php $tpnb = 5; test(); die(); function test() { global $tpnb; var_dump($tpnb); $xmlStruct = <<<EOF <?xml version="1.0" encoding="UTF-8"?> <templates> <object type="obj_1" label="Label for object 1"></object> <object type="obj_2" label="Label for object 2"></object> <object type="obj_3" label="Label for object 3"></object> <object type="obj_4" label="Label for object 4"></object> <object type="obj_5" label="Label for object 5"></object> <object type="obj_6" label="Label for object 6"></object> <object type="obj_7" label="Label for object 7"></object> <object type="obj_8" label="Label for object 8"></object> <object type="obj_9" label="Label for object 9"></object> <object type="obj_10" label="Label for object 10"></object> </templates> EOF; $tplxml = simplexml_load_string($xmlStruct); var_dump($tplxml->object[$tpnb]); var_dump($tplxml->object[(int) $tpnb]); var_dump($tplxml->object[($tpnb + 1 - 1)]); $tpnbx = $tpnb; unset($tpnb); $tpnb = $tpnbx; var_dump($tplxml->object[$tpnb]); }
based on OcRGM
Output for 5.1.2 - 5.6.30, 7.0.10 - 7.2.6
int(5) object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(2) { ["type"]=> string(5) "obj_6" ["label"]=> string(18) "Label for object 6" } } object(SimpleXMLElement)#3 (1) { ["@attributes"]=> array(2) { ["type"]=> string(5) "obj_6" ["label"]=> string(18) "Label for object 6" } } object(SimpleXMLElement)#2 (1) { ["@attributes"]=> array(2) { ["type"]=> string(5) "obj_6" ["label"]=> string(18) "Label for object 6" } } object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(2) { ["type"]=> string(5) "obj_6" ["label"]=> string(18) "Label for object 6" } }
Output for 7.0.0 - 7.0.9
int(5) NULL object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(2) { ["type"]=> string(5) "obj_6" ["label"]=> string(18) "Label for object 6" } } object(SimpleXMLElement)#3 (1) { ["@attributes"]=> array(2) { ["type"]=> string(5) "obj_6" ["label"]=> string(18) "Label for object 6" } } object(SimpleXMLElement)#2 (1) { ["@attributes"]=> array(2) { ["type"]=> string(5) "obj_6" ["label"]=> string(18) "Label for object 6" } }
Output for 5.0.0 - 5.1.1
int(5) object(SimpleXMLElement)#4 (0) { } object(SimpleXMLElement)#3 (0) { } object(SimpleXMLElement)#2 (0) { } object(SimpleXMLElement)#4 (0) { }
Output for 4.4.5 - 4.4.9
int(5) Fatal error: Call to undefined function: simplexml_load_string() in /in/IiZvt on line 29
Process exited with code 255.
Output for 4.3.2 - 4.4.1, 4.4.3 - 4.4.4
int(5) Fatal error: Call to undefined function: simplexml_load_string() in /in/IiZvt on line 29
Process exited with code 255.
Output for 4.4.2
int(5) Fatal error: Call to undefined function: simplexml_load_string() in /in/IiZvt on line 30
Process exited with code 255.
Output for 4.3.0 - 4.3.1
int(5) Fatal error: Call to undefined function: simplexml_load_string() in /in/IiZvt on line 29