php.net |  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
Votes:16
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
37 - 34 = ?
Subscribe to this entry?

 
 [2012-06-01 07:43 UTC] phpdev at mailmetrash dot com
Description:
------------
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('
<person>
  <profile>
    <name>PHP developer</name>
  </profile>
</person>');

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

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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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.

Stuart
 [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] salathe@php.net
-Status: Open +Status: Duplicate
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC