Wrong "syntax error" for XML in PHP7.3 HEREDOC block

This screenshot explains the problem:

So the parser "thinks" that those indentation spaces are part of the document, which is wrong.

0
3 comments

Is this a working code (with indent)? 

In fact, I just tried a similar construction and got the following from interpreter:

PHP Warning: SimpleXMLElement::__construct(): Entity: line 1: parser error : XML declaration allowed only at the start of the document in ...

 

0

Yes, this is working code. Just tried it with SimpleXMLElement and it works correctly. If I add more spaces to the first line, then I get the same exception (which is corrent behavior). But with equal indentation level it works great.

0

Could you please attach a sample code file that works for you? 

Doing something like 

<?php
$a = <<<XML
    <?xml version="1.0" encoding="windows-1250" ?>
    <tag>111</tag>
XML;
$document = new DOMDocument();
$document->loadXML($a);

doesn't reproduce the behavior you're getting for us, unfortunately.

 

0

Please sign in to leave a comment.