I'm refactoring some PHP code and discovered that certain nested combinations of
if () :
and
if () {
generate syntax errors. Not that I would normally mix the two, but I like to do frequent syntax checks as I'm writing code and I kept getting a syntax error because of this.
Example - generates syntax error:
if ( $test == 1 ) :
if ( $test2 == 'a' ) {
if ( $test3 == 'A' ) {
} else {
}
}
else :
echo 'test2';
endif;
Example - does NOT generate syntax error:
if ( $test == 1 ) :
if ( $test2 == 'a' ) :
if ( $test3 == 'A' ) :
else :
endif;
endif;
else :
echo 'test2';
endif;
Could someone please explain to me why the first block of code is generating an error?