I've answered a question today that had a simple solution, but I've yet to understand why it was something for which the PHP interpreter didn't throw a syntax error. So my question is simple:
Why are the statements below considered to have valid syntax?
SomeIdentifier:;
AnythingGoesApparently:;
ThisCanGoOnAndOn:;
Even more so since those identifiers are not defined anywhere.
To my knowledge the colon :
is only used as part of two operators: The Scope Resolution Operator, The Ternary Operator, but not on its own. It's also used in the Alternative syntax for control structures. But none of these would qualify in this case, so this is bugging me like crazy.
What Does Syntax Validation Mean? Syntax validation is the process of checking whether the syntax of a program is free of programming or stylistic editors. There are a number of tools to check syntax for almost every programming language. Some are run locally on the computer and others are available online.
I believe these would be interpreted as goto
labels.
For example:
$x = 0;
goto ThisIsBad;
$x++;
ThisIsBad:
$x += 2;
echo $x;
Output: 2
Reference: http://php.net/manual/en/control-structures.goto.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With