php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #42289 xpath relative paths incorrectly returns no match
Submitted: 2007-08-14 01:12 UTC Modified: 2007-08-20 14:53 UTC
From: cpriest at warpmail dot net Assigned: rrichards (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.2.4RC1 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cpriest at warpmail dot net
New email:
PHP Version: OS:

 

 [2007-08-14 01:12 UTC] cpriest at warpmail dot net
Description:
------------
Non-absolute paths using ->xpath() do not match appropriately.  With the  given example, changing the xpath to '/postresponse/status/@accept' correctly returns "no"

Reproduce code:
---------------
<?
	$ResponseBody = '<?xml version="1.0" encoding="UTF-8"?><postresponse><status accept="no">INVALID</status></postresponse>';
	
	$objXML = new SimpleXMLElement($ResponseBody);
	
	$tMatches = $objXML->xpath('postresponse/status/@accept');
	print_r((string)$tMatches[0]);
?>

Expected result:
----------------
"no"

Actual result:
--------------
xpath() returns no results

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-14 11:56 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

output is correct. $objXML is document element
 [2007-08-15 14:27 UTC] cpriest at warpmail dot net
According to the specs:
> Always returns an array of SimpleXMLElement objects.

While the xpath() is actually returning a boolean value.  Here is some revised code which demonstrates an incorrect return value:

<?php
    require_once('inc.backend.interactive.php');
    header('Content-Type: text/plain');
    set_time_limit(0);
   
    $ResponseBody = '<?xml version="1.0" encoding="UTF-8"?><postresponse><status accept="no">INVALID</status></postresponse>';
   
    $objXML = new SimpleXMLElement($ResponseBody);
   
    $tMatches = $objXML->xpath('postresponse/status/@accept');
    print_r($tMatches);
    print_r(gettype($tMatches));
//    print_r((string)$tMatches[0]);
?>
 [2007-08-17 13:39 UTC] jani@php.net
Rob, you didn't get away that easy. :)
 [2007-08-18 10:11 UTC] rrichards@php.net
re-classifying as documentation issue. xpath() returns boolean on failure.
 [2007-08-20 14:53 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Returns an array of SimpleXMLElement objects or FALSE in case of an error."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 11:01:37 2025 UTC