php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53998 SimpleXMLElement constructor can trigger an error without throwing an exception
Submitted: 2011-02-11 21:37 UTC Modified: 2011-06-29 18:29 UTC
From: aaron dot brown+php at oakadaptive dot com Assigned: mfonda (profile)
Status: Closed Package: SimpleXML related
PHP Version: 5.3.5 OS:
Private report: No CVE-ID: None
 [2011-02-11 21:37 UTC] aaron dot brown+php at oakadaptive dot com
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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-06-29 18:29 UTC] mfonda@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: mfonda
 [2011-06-29 18:29 UTC] mfonda@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 07 14:01:32 2024 UTC