php.net |  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: 2017-01-28 12:19 UTC
Votes:1
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:
Status: Open Package: XML Reader
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-03-20 17:05 UTC] halil dot ozgur at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/xmlreader.next
---
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:
---------------
<?php
$itemTag = "test";
$xml = <<<EOX
<?xml version="1.0" encoding="utf-8"?>
<tests>
    <test>
        <lorem>11111</lorem>
    </test>
    <test>
        <lorem>22222</lorem>
    </test>
</tests>
EOX;
$reader = new \XMLReader();
$reader->XML($xml);
// move to the first element
while ($reader->read() && $reader->name !== $itemTag) {}
echo "Current: " . $reader->name . "\n";
$reader->next($itemTag);
$reader->next($itemTag);
echo "Current: " . $reader->name . "\n";


Expected result:
----------------
Current: test
Current: test

Actual result:
--------------
Current: test
Current:

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-01-28 12:19 UTC] cmb@php.net
-Package: Documentation problem +Package: XML Reader
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Apr 22 02:01:25 2019 UTC