From: Operating system: Windows XP PHP version: 5.3.5 Package: SimpleXML related Bug Type: Bug Bug description:SimpleXMLElement does not read XML declaration line.
Description: ------------ --- >From manual page: http://www.php.net/simplexml.examples-basic --- When I run the first example I get the following errors: $ php test1.php Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : XML declaration allowed only at the start of th e document in D:\php_src\XML\test1.php on line 4 Warning: SimpleXMLElement::__construct(): <?xml version="1.0" encoding="utf-8"?> in D:\php_src\XML\test1.php on li ne 4 Warning: SimpleXMLElement::__construct(): ^ in D:\php_src\XML\test1.php on line 4 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in D:\php_src\XML\test1.php :4 Stack trace: #0 D:\php_src\XML\test1.php(4): SimpleXMLElement->__construct('?<?xml version=...') #1 {main} thrown in D:\php_src\XML\test1.php on line 4 If I remove the <?xml version="1.0" encoding="utf-8"?> line from the example.php file it runs ok. So how do we handle the declaration line for xml files with SimpleXMLElement? Test script: --------------- Just running example 2 from http://www.php.net/manual/en/simplexml.examples-basic.php Expected result: ---------------- Expected result: So, this language. It's like, a programming language. Or is it a scripting language? All is revealed in this thrilling horror spoof of a documentary. Actual result: -------------- $ php test1.php Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : XML declaration allowed only at the start of th e document in D:\php_src\XML\test1.php on line 4 Warning: SimpleXMLElement::__construct(): <?xml version="1.0" encoding="utf-8"?> in D:\php_src\XML\test1.php on li ne 4 Warning: SimpleXMLElement::__construct(): ^ in D:\php_src\XML\test1.php on line 4 Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in D:\php_src\XML\test1.php :4 Stack trace: #0 D:\php_src\XML\test1.php(4): SimpleXMLElement->__construct('?<?xml version=...') #1 {main} thrown in D:\php_src\XML\test1.php on line 4 -- Edit bug report at http://bugs.php.net/bug.php?id=53694&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53694&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53694&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53694&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53694&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53694&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53694&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53694&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53694&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53694&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53694&r=support Expected behavior: http://bugs.php.net/fix.php?id=53694&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53694&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53694&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53694&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53694&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53694&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53694&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53694&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53694&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53694&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53694&r=mysqlcfg