Why is this syntax valid?

Today I answered a question that had a simple solution, but I still did not understand why it was something for which the PHP interpreter doesn’t throw a syntax error. Therefore, my question is simple:

Why is there a valid syntax in the statements below?

SomeIdentifier:; AnythingGoesApparently:; ThisCanGoOnAndOn:; 

Moreover, these identifiers are not defined anywhere.


As far as I know, a colon : used only as part of two operators: The scope resolution operator , the Turner operator , but not by itself. It is also used in alternative syntax for control structures . But in this case, none of them will qualify, so this undermines me as a madman.

+6
source share
1 answer

I believe that they will be interpreted as goto tags.

For instance:

 $x = 0; goto ThisIsBad; $x++; ThisIsBad: $x += 2; echo $x; 

Output: 2

Link: http://php.net/manual/en/control-structures.goto.php

+6
source

All Articles