Alright so I’ve already created a PHP bug about this but it was marked as bogus, but I can’t help but to believe they didn’t read it carefully…
The error is caused by using an include() statement in an IF statement, making the statement believe it’s been passed an empty string.
Reviewing the bug will explain everything, including a test script.
Is it a bug, or am I missing something “feature”-wise? This is weird seeing as how assigning the output of include to a variable and then testing that value works just fine (which would be the workaround).
Well, the documentation says:
So this behaviour is already known and not considered as a bug. You even have an explanation why it works this way:
includedoes not need parenthesis, so PHP does not really whether you want to do:or
It seems that it is implemented to interpet it as the latter (something like the longest possible match).
Same goes for
which PHP interprets as
and tries to load
foobar.But the solution is also given: Wrap the whole include statement into parenthesis, then there is only one way how PHP can interpret the call:
(Maybe) off topic: You will find similar “issues” in other parts of PHP. Take variable variables:
PHP does not know whether you want to access the
barelement of the array$fooand use this value as property name:or if you want to access the
barelement of$obj->$foo:In all these cases, there is a default behaviour of the parser. The developers decided for one possibility because they had to. It might not be what you expect, but if you know it, you can deal with it.
This behaviour cannot simply be changed as it might break code that relies on this behaviour.