Doc #53998 [Opn->Csd]: SimpleXMLElement constructor can trigger an error without throwing an exception

From: Date: Wed, 29 Jun 2011 22:29:12 +0000
Subject: Doc #53998 [Opn->Csd]: SimpleXMLElement constructor can trigger an error without throwing an exception
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-6763@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=53998&edit=1 ID: 53998 Updated by: mfonda@php.net Reported by: aaron dot brown+php at oakadaptive dot com Summary: SimpleXMLElement constructor can trigger an error without throwing an exception -Status: Open +Status: Closed Type: Documentation Problem Package: SimpleXML related PHP Version: 5.3.5 -Assigned To: +Assigned To: mfonda Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2011-02-11 21:37:46] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=53998&edit=1

« previous php.doc.bugs (#6763) next »