Doc #53998 [NEW]: SimpleXMLElement constructor can trigger an error without throwing an exception
| From: | aaron dot brown+php at oakadaptive dot com | Date: | Fri, 11 Feb 2011 20:37:47 +0000 |
| Subject: | Doc #53998 [NEW]: SimpleXMLElement constructor can trigger an error without throwing an exception | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-5979@lists.php.net to get a copy of this message | ||
From:
Operating system:
PHP version: 5.3.5
Package: SimpleXML related
Bug Type: Documentation Problem
Bug description:SimpleXMLElement constructor can trigger an error without throwing an exception
Description:
------------
The documentation at
http://www.php.net/manual/en/simplexmlelement.construct.php
says:
> Produces an E_WARNING error message for each error found
> in the XML data and throws an exception if errors were
> detected.
However, in the following example, SimpleXMLElement's
constructor triggers an error but does not throw an
exception. (I suppose this is because the xmlReadMemory
call on line 2201 of ext/simplexml/simplexml.c triggers an
error but still returns an XML document.)
(To be specific, it triggers three errors -- one that
"'bogus bogus' is not a valid URI" and two more to show the
position of the problem in the XML.)
I filed this as a documentation problem; the documentation
says (or at least implies, depending on the interpretation
of "error found in the XML data") that if there are one or
more PHP errors triggered, an exception will be thrown. The
fix would be to clarify the documentation as to the types of
errors that will result in exceptions. Alternatively, the
behavior could be changed to match the documentation.
Thanks!
Test script:
---------------
$Sxe = new SimpleXMLElement('<foo xmlns:bar="bogus bogus"></foo>');
echo "This is reached even though 'bogus bogus' triggered an error\n";
Expected result:
----------------
Errors and an exception. (Or no error and no exception.)
Actual result:
--------------
PHP Warning: SimpleXMLElement::__construct(): namespace error : xmlns:bar:
'bogus bogus' is not a valid URI in /home/adb/s/oa/env/trunk/del.php on
line 3
PHP Warning: SimpleXMLElement::__construct(): <foo xmlns:bar="bogus
bogus"></foo> in /home/adb/s/oa/env/trunk/del.php on line 3
PHP Warning: SimpleXMLElement::__construct():
^ in /home/adb/s/oa/env/trunk/del.php on line 3
This is reached even though 'bogus bogus' triggered an error
--
Edit bug report at http://bugs.php.net/bug.php?id=53998&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53998&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53998&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53998&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=53998&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53998&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=53998&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=53998&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=53998&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=53998&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=53998&r=support
Expected behavior: http://bugs.php.net/fix.php?id=53998&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=53998&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=53998&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=53998&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53998&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53998&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=53998&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=53998&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=53998&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=53998&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=53998&r=mysqlcfg