Bug->Doc #55230 [Opn]: Wrong return value for getAttribute
| From: | pajoye@php.net | Date: | Mon, 18 Jul 2011 12:13:50 +0000 |
| Subject: | Bug->Doc #55230 [Opn]: Wrong return value for getAttribute | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-6896@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=55230&edit=1
ID: 55230
Updated by: pajoye@php.net
Reported by: evoloshchuk at gmail dot com
Summary: Wrong return value for getAttribute
Status: Open
-Type: Bug
+Type: Documentation Problem
Package: XML Reader
Operating System: Mac OS X 10.6.3
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
The documentation is wrong.
An attribute can have an empty string as value, so an empty string cannot be
used to indicate that the requested attribute does not exist.
NULL is used for this purpose, as described in the XmlReader MSDN
documentations, which is the specs for the php's xmlreader and writer (see
http://msdn.microsoft.com/en-us/library/sxy2cd1w.aspx).
Actually we should maybe
return NULL for empty value as well. But that could break some code out there.
Previous Comments:
------------------------------------------------------------------------
[2011-07-18 08:07:31] evoloshchuk at gmail dot com
Description:
------------
According to the spec at http://php.net/manual/en/xmlreader.getattribute.php
Return Values
The value of the attribute, or an empty string if no attribute with the given name is found or not
positioned of element.
The actual return value in case if no attribute found is NULL, instead of empty string.
Test script:
---------------
<?php
$reader = new XmlReader();
$reader->xml('<?xml version="1.0"
encoding="UTF-8"?><a></a>');
$reader->read();
var_dump($reader->getAttribute('x'));
?>
Expected result:
----------------
string(0) ""
Actual result:
--------------
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=55230&edit=1