3v4l.org

run code in 300+ PHP versions simultaneously
<?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> <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->duration->children('yt', TRUE)->attributes()->seconds, "\n"; echo 'via array-access: ', $youtube->entry->duration->children('yt', TRUE)['seconds'], "\n"; echo 'via property : ', $youtube->entry->duration->children('yt', TRUE)->seconds, "\n";
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
ibxml version: 2.9.4 via attributes(): Warning: Attempt to read property "seconds" on null in /in/epKWJ on line 24 via array-access: via property :
Output for 5.6.28, 7.0.20, 7.1.0 - 7.1.7, 7.1.20 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
ibxml version: 2.9.4 via attributes(): Warning: main(): Node no longer exists in /in/epKWJ on line 24 Warning: main(): Node no longer exists in /in/epKWJ on line 24 via array-access: via property :
Output for 7.1.10
ibxml version: 2.9.5 via attributes(): Warning: main(): Node no longer exists in /in/epKWJ on line 24 Warning: main(): Node no longer exists in /in/epKWJ on line 24 via array-access: via property :
Output for 5.5.24 - 5.5.35, 5.6.7 - 5.6.15, 5.6.17 - 5.6.21, 7.0.1 - 7.0.6
ibxml version: 2.9.3 via attributes(): Warning: main(): Node no longer exists in /in/epKWJ on line 24 Warning: main(): Node no longer exists in /in/epKWJ on line 24 via array-access: via property :
Output for 5.4.0 - 5.4.45, 5.6.16, 7.0.0
ibxml version: 2.9.2 via attributes(): Warning: main(): Node no longer exists in /in/epKWJ on line 24 Warning: main(): Node no longer exists in /in/epKWJ on line 24 via array-access: via property :
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ',' or ';' in /in/epKWJ on line 25
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[', expecting ',' or ';' in /in/epKWJ on line 25
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/epKWJ on line 24
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in /in/epKWJ on line 24
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `','' or `';'' in /in/epKWJ on line 24
Process exited with code 255.

preferences:
221.31 ms | 401 KiB | 323 Q