Doc #64470 [Opn->Ver]: XMLReader::next($localname) moves cursor even if there is no more $localname
Edit report at https://bugs.php.net/bug.php?id=64470&edit=1
ID: 64470
Updated by: cmb@php.net
Reported by: halil dot ozgur at gmail dot com
Summary: XMLReader::next($localname) moves cursor even if
there is no more $localname
-Status: Open
+Status: Verified
Type: Documentation Problem
Package: XML Reader
Operating System: Irrelevant
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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
case.
Previous Comments:
------------------------------------------------------------------------
[2013-03-20 17:05:42] 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:
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64470&edit=1
Thread (3 messages)