|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #64470 XMLReader::next($localname) moves cursor even if there is no more $localname
Submitted: 2013-03-20 17:05 UTC Modified: 2021-01-13 13:29 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: halil dot ozgur at gmail dot com Assigned: cmb (profile)
Status: Closed Package: XML Reader
PHP Version: Irrelevant OS: Irrelevant
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: halil dot ozgur at gmail dot com
New email:
PHP Version: OS:


 [2013-03-20 17:05 UTC] halil dot ozgur at gmail dot com
From manual page:
I'm not sure if this obvious, or is not a bug. next() method when invoked with a 
parameter (with $localname non-empty) moves the cursor even if there is no more 
$localname items and next() returns false. This in fact proved helpful for me 
while implementing a custom iterator. But it could still be useful to include this 
information in the documentation.

Test script:
$itemTag = "test";
$xml = <<<EOX
<?xml version="1.0" encoding="utf-8"?>
$reader = new \XMLReader();
// move to the first element
while ($reader->read() && $reader->name !== $itemTag) {}
echo "Current: " . $reader->name . "\n";
echo "Current: " . $reader->name . "\n";

Expected result:
Current: test
Current: test

Actual result:
Current: test


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-28 12:19 UTC]
-Package: Documentation problem +Package: XML Reader
 [2020-10-07 14:13 UTC]
-Status: Open +Status: Verified
 [2020-10-07 14:13 UTC]
Indeed, if there are no more respective nodes, the cursor is moved
to the end of the document.  While the underlying
xmlTextReaderName()'s result distinguished that (-1) from other
error conditions (0), XMLReader::next() returns FALSE in either
 [2021-01-13 13:26 UTC]
-Assigned To: +Assigned To: cmb
 [2021-01-13 13:29 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 08:01:28 2024 UTC