3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $content = <<<XML <?xml version="1.0" encoding="ISO-8859-1"?> <PersonList> <Header> </Header> <Person> <Name id="35" atrib="LOL">Sonu Kapoor</Name> <Age>24</Age> <Gender>M</Gender> <PostalCode>54879</PostalCode> </Person> <Person> <Name>Jasmin</Name> <Age>28</Age> <Gender>M</Gender> <PostalCode>78745</PostalCode> </Person> <Person> <Name>Josef</Name> <Age>232</Age> <Gender>F</Gender> <PostalCode>53454</PostalCode> </Person> </PersonList> XML; $doc = new DOMDocument(); $doc->loadXML($content); $xp = new DOMXPath($doc); foreach($xp->query('/PersonList/Header/Person/Name@atrib[. != ""]') as $attrib) { $attrib->nodeValue = 'yes'; } echo $doc->saveXML();
Output for 5.1.0 - 5.1.1, 5.1.3 - 5.6.28, 7.0.0 - 7.1.0
Warning: DOMXPath::query(): Invalid expression in /in/KhIEH on line 32 Warning: Invalid argument supplied for foreach() in /in/KhIEH on line 32 <?xml version="1.0" encoding="ISO-8859-1"?> <PersonList> <Header> </Header> <Person> <Name id="35" atrib="LOL">Sonu Kapoor</Name> <Age>24</Age> <Gender>M</Gender> <PostalCode>54879</PostalCode> </Person> <Person> <Name>Jasmin</Name> <Age>28</Age> <Gender>M</Gender> <PostalCode>78745</PostalCode> </Person> <Person> <Name>Josef</Name> <Age>232</Age> <Gender>F</Gender> <PostalCode>53454</PostalCode> </Person> </PersonList>
Output for hhvm-3.10.0 - 3.13.2
Warning: Invalid argument supplied for foreach() in /in/KhIEH on line 35 <?xml version="1.0" encoding="ISO-8859-1"?> <PersonList> <Header> </Header> <Person> <Name id="35" atrib="LOL">Sonu Kapoor</Name> <Age>24</Age> <Gender>M</Gender> <PostalCode>54879</PostalCode> </Person> <Person> <Name>Jasmin</Name> <Age>28</Age> <Gender>M</Gender> <PostalCode>78745</PostalCode> </Person> <Person> <Name>Josef</Name> <Age>232</Age> <Gender>F</Gender> <PostalCode>53454</PostalCode> </Person> </PersonList> XPath error : Invalid expression /PersonList/Header/Person/Name@atrib[. != ""] ^
Output for 5.1.2
Warning: DOMXPath::query(): Invalid expression in /in/KhIEH on line 33 Warning: Invalid argument supplied for foreach() in /in/KhIEH on line 33 <?xml version="1.0" encoding="ISO-8859-1"?> <PersonList> <Header> </Header> <Person> <Name id="35" atrib="LOL">Sonu Kapoor</Name> <Age>24</Age> <Gender>M</Gender> <PostalCode>54879</PostalCode> </Person> <Person> <Name>Jasmin</Name> <Age>28</Age> <Gender>M</Gender> <PostalCode>78745</PostalCode> </Person> <Person> <Name>Josef</Name> <Age>232</Age> <Gender>F</Gender> <PostalCode>53454</PostalCode> </Person> </PersonList>
Output for 5.0.0 - 5.0.5
Warning: Invalid expression in /in/KhIEH on line 32 Warning: Invalid argument supplied for foreach() in /in/KhIEH on line 32 <?xml version="1.0" encoding="ISO-8859-1"?> <PersonList> <Header> </Header> <Person> <Name id="35" atrib="LOL">Sonu Kapoor</Name> <Age>24</Age> <Gender>M</Gender> <PostalCode>54879</PostalCode> </Person> <Person> <Name>Jasmin</Name> <Age>28</Age> <Gender>M</Gender> <PostalCode>78745</PostalCode> </Person> <Person> <Name>Josef</Name> <Age>232</Age> <Gender>F</Gender> <PostalCode>53454</PostalCode> </Person> </PersonList>
Output for 4.3.2 - 4.4.1, 4.4.3 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/KhIEH on line 28
Process exited with code 255.
Output for 4.4.2
Fatal error: Cannot instantiate non-existent class: domdocument in /in/KhIEH on line 29
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/KhIEH on line 28