3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $xml=simplexml_load_string(<<<XML <inventory> <products> <product id="001"> <name>Shirt 1 - Women's</name> <price>12.00</price> <color>blue</color> </product> <product id="002"> <name>Shirt 1 - Men's</name> <price>12.00</price> <color>red</color> </product> <product id="023"> <name>Shirt 12 - Women's</name> <price>15.00</price> <color>purple</color> </product> <product id="024"> <name>Shirt 12 - Men's</name> <price>15.00</price> <color>yellow</color> </product> </products> </inventory> XML ); $a = 23; foreach($xml->xpath('///product[@id=intval($a) or @id="024"]') as $product) { echo $product->attributes()->id; echo "\n"; echo $product->name; echo "\n"; echo $product->price; echo "\n"; echo $product->color; echo "\n\n"; }
Output for 5.1.0 - 5.1.1, 5.1.3 - 7.1.0
Warning: SimpleXMLElement::xpath(): xmlXPathEval: 2 object left on the stack in /in/q7T17 on line 35 Warning: Invalid argument supplied for foreach() in /in/q7T17 on line 35
Output for 5.1.2
Warning: SimpleXMLElement::xpath(): xmlXPathEval: 2 object left on the stack in /in/q7T17 on line 36 Warning: Invalid argument supplied for foreach() in /in/q7T17 on line 36
Output for 5.0.0 - 5.0.5
Warning: xmlXPathEval: 2 object left on the stack in /in/q7T17 on line 35 Warning: Invalid argument supplied for foreach() in /in/q7T17 on line 35
Output for 4.4.3 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/q7T17 on line 37
Process exited with code 255.
Output for 4.4.2
Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/q7T17 on line 38
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/q7T17 on line 37
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `','' or `';'' in /in/q7T17 on line 37
Process exited with code 255.