|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62203 xpath doesn't return tag values
Submitted: 2012-06-01 07:43 UTC Modified: 2013-02-18 21:21 UTC
Avg. Score:4.3 ± 0.9
Reproduced:15 of 15 (100.0%)
Same Version:11 (73.3%)
Same OS:6 (40.0%)
From: phpdev at mailmetrash dot com Assigned:
Status: Duplicate Package: SimpleXML related
PHP Version: 5.4.3 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: phpdev at mailmetrash dot com
New email:
PHP Version: OS:


 [2012-06-01 07:43 UTC] phpdev at mailmetrash dot com
In PHP 5.4 xpath() returns SimpleXMLObjects which casted to array give empty arrays. If tags have text values they aren't present in object like in PHP 5.3.

Test script:
$xml = simplexml_load_string('
    <name>PHP developer</name>

// get all names
$xml = $xml->xpath('/person/profile/name');
// get first result
$xml = reset($xml);
// show result

Expected result:
In PHP 5.3 the (expected) result is
SimpleXMLElement Object ( [0] => PHP developer )

Casting this to an array will result: array(0 => 'PHP developer') which is ok.

Actual result:
In PHP 5.4 the result is 
SimpleXMLElement Object ( )

If we cast this to an array will result an empty array, but we expected text values.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-16 21:37 UTC] schalk at unf dot edu
When is this going to be fixed.  I have reproduced it in 5.4.11 and it is kind of a major bug that has caused me a significant amount of wasted debug time.

 [2013-02-16 21:48 UTC] schalk at unf dot edu
I just checked and this is not fixed in 5.5.0alpha4 either!  Do I really have to go back to 5.3?
 [2013-02-18 18:30 UTC] schalk at unf dot edu
I checked both the current 5.3 and 5.4 source for the xpath simplexml function and they are the same.  So, this means that the error is somewhere else.  Could this be because of the change in how 5.4 deals with arrays?
 [2013-02-18 21:21 UTC]
-Status: Open +Status: Duplicate
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 04:01:28 2024 UTC