3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** * How to get attribute of node with namespace using SimpleXML? * * @link http://stackoverflow.com/q/6576773/367456 */ $buffer = '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:yt="http://gdata.youtube.com/schemas/2007"> <entry> <yt:duration seconds="1870" yt:seconds="0 in yt namespace" /> </entry> </feed>'; $xml = new SimpleXMLElement($buffer); if (!defined('LIBXML_DOTTED_VERSION')) { echo "PHP/LIBXML unsupported/too old."; return; } echo "ibxml version: ", LIBXML_DOTTED_VERSION, "\n"; $youtube = $xml; echo 'via attributes(): ', $youtube->entry->children('yt', TRUE)->duration->attributes()->seconds, "\n"; echo 'via array-access: ', $youtube->entry->children('yt', TRUE)->duration['seconds'], "\n"; echo 'via property : ', $youtube->entry->children('yt', TRUE)->duration->seconds, "\n";
Output for 5.5.36 - 5.5.38, 5.6.22 - 5.6.28, 7.0.7 - 7.1.0
ibxml version: 2.9.4 via attributes(): 1870 via array-access: 0 in yt namespace via property :
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.21, hhvm-3.12.0, 7.0.0 - 7.0.6
ibxml version: 2.9.3 via attributes(): 1870 via array-access: 0 in yt namespace via property :
Output for 5.4.0 - 5.4.45, hhvm-3.10.0
ibxml version: 2.9.2 via attributes(): 1870 via array-access: 0 in yt namespace via property :
Output for 5.3.25 - 5.3.29
ibxml version: 2.9.1 via attributes(): 1870 via array-access: 0 in yt namespace via property :
Output for 5.3.15 - 5.3.24
ibxml version: 2.8.0 via attributes(): 1870 via array-access: 0 in yt namespace via property :
Output for 5.2.0 - 5.3.14
ibxml version: 2.7.8 via attributes(): 1870 via array-access: 0 in yt namespace via property :
Output for 5.1.0 - 5.1.6
ibxml version: 2.7.8 via attributes(): Warning: SimpleXMLElement::children() expects at most 1 parameter, 2 given in /in/kR3vP on line 24 Notice: Trying to get property of non-object in /in/kR3vP on line 24 Fatal error: Call to a member function attributes() on a non-object in /in/kR3vP on line 24
Process exited with code 255.
Output for 5.0.0 - 5.0.5
PHP/LIBXML unsupported/too old.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/kR3vP on line 24
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/kR3vP on line 24
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `','' or `';'' in /in/kR3vP on line 24
Process exited with code 255.