samedi 9 septembre 2017

PHP if... else alternative syntax throwing "unexpected ':' in..." error message

I need some help with the below alternative if-else syntax. I use this very frequently and it works with a 99.999999% success rate. Here, for some reason, it doesn't:

if ( get_row_layout() == 'spacer' ) : 

    $spaceheight = get_sub_field('spacer_height');

    // The Alternative Syntax: if... else statement without a colon
    // Once these two lines are removed OR changed into "if ( some
    // condition ) : some stuff; endif;" syntax >> the error goes
    // away. 
    if ( $spaceheight && ( 0 !== $spaceheight ) )
        echo "<div class='nuvem-spacer' style='display: block; width: 100%; height: {$spaceheight}px; background: transparent; padding: 0; margin: 0; font-size: 0; line-height: 0;'></div>";

elseif ( get_row_layout() == 'terms' ) :

    // Some other stuff

endif;

The specific error message is: "Parse error: syntax error, unexpected ':' in... "; and the colon is unexpected after the alternative syntax, in the elseif ( get_row_layout() == 'terms' ) : line.

Any idea what's happening here?

Aucun commentaire:

Enregistrer un commentaire