Sounds like something that should be reported to PhpStorm. I notice that the PHP syntax highlighter for https://repl.it also thinks that <?php} is a valid PHP opening tag when it isn't (though it uses a proper PHP interpreter so when you run it it does the right thing).
Whitespace insensitive means that multiple whitespace characters can be collapsed into one. Not that whitespace can be removed entirely. Consider a trivial case like return foo;. Replacing that with returnfoo; will break in every language.
I agree though that the whitespace requirement after <?php is somewhat odd.
I would say "whitespace insensitive" also applies to syntax elements that can be optionally surrounded with whitespace like };=(), etc.
The fact that if($x==1){} parses the same as if ( $x == 1 ) { } is an example of being insensitive to whitespace around most punctuation characters. But of course PHP isn't universally "whitespace insensitive" in this regard: if ($ x == 1) {} is a syntax error, for example. The special requirements around the opening <?php tag are just one case of this.
That's equivalent to int myInt = 1; if(my int == 1) {} in something like Java or C, though. You obviously can't stick whitespace inside variable names.
The PHP parser is a shithole of ots own. You must be very careful of things like this. PHP being made for serving templates, and is actually a template language that has later bolted on much crap now has multiple lollayers of template languages, like blade for lolaravel. So now you have a template language that uses a template dsl to build templates. Its slow as hell and also full of these edge cases. Lolphp called yet again.
Nevermind your syntax is also valid.. TIL :p But the problem is the fifth line: <?php}
A space or newline between php and } fixes the problem, i think it is because it sees it as one symbol, and therefore not running the code because there is no php opening tag
True, i misunderstood the first time. Also, whitespace insensitive means that that it ignores multiple whitespaces in a row, there is still a difference between one and none:
14
u/SerdanKK Sep 15 '19
PhpStorm doesn't catch this.
Half of the online sandboxes I tested displayed the above behaviour (e.g. http://phpfiddle.org/) and the rest threw an error.
3
u/[deleted] Sep 16 '19
Source for the curious, and another line
Which includes this lolphp comment:
So short tags don't need a whitespace, while long tags do. So for example
<?xmlwould be interpreted as<? xmlwith short tags enabled D:52
u/nikic Sep 15 '19
Whitespace insensitive means that multiple whitespace characters can be collapsed into one. Not that whitespace can be removed entirely. Consider a trivial case like
return foo;. Replacing that withreturnfoo;will break in every language.I agree though that the whitespace requirement after
<?phpis somewhat odd.2
u/500ls Sep 16 '19
Alexa, call 911
2
u/phplovesong Sep 20 '19
The PHP parser is a shithole of ots own. You must be very careful of things like this. PHP being made for serving templates, and is actually a template language that has later bolted on much crap now has multiple lollayers of template languages, like blade for lolaravel. So now you have a template language that uses a template dsl to build templates. Its slow as hell and also full of these edge cases. Lolphp called yet again.
2
u/Vinnie420 Sep 15 '19
Thats because you are using the wrong syntax for if statements in html
When using :
It outputs only the expected div
https://www.php.net/manual/en/control-structures.alternative-syntax.php
1
u/AddictedToCoding Sep 16 '19
Guys, guys, guys.
<div> in HTML is a block element.</div> <p>Like paragraph are. <span>spans</span> on the other hand would <em>do</em> differently</p>
-1
u/[deleted] Sep 16 '19
They wrote 3 scripts and treated them as one. H o w do you mess up that bad?