mercredi 20 septembre 2017

If/or statement throwing error in php 5.3.10

I have an if statement which is throwing a syntax error, unexpected T_VARIABLE error and I have no idea why.

The code:

<?php if($contentTop || $contentLeft || $contentCenter || $contentRight): ?>
  <div>a bunch of html</div>
<?php endif; ?>

The variable contains eiter an empty string or a bunch of html.

I have tried changing the || to or but it doesn't seem to change anything. neither does opening and closing the if statement with curly brackets. It only seems to work when i only have one variable in the statement. I have also tried using !empty($contentTop) to check the variables.

The server is running PHP version 5.3.10-1ubuntu3.26 but as far as I can see, that should not change anything regarding if statements

EDIT:

On request of the full markup:

<?php 
$contentTop = get_field('section2new_content');
$contentLeft = get_field('section2new_left');
$contentCenter = get_field('section2new_center');
$contentRight = get_field('section2new_right');


if( $contentTop || $contentLeft || $contentCenter || $contentRight ): ?>

    <div class="bbh-inner-section teaser-3-col" id="section2temp">
        <?php if($contentTop): ?>
            <div class="grid-container top">
                <div class="row">
                    <div class="col-sm-12">
                        <?php echo $contentTop; ?>
                    </div>
                </div>  
            </div>
        <?php endif; ?>
        <?php if($contentLeft || $contentRight || $contentCenter): ?>
            <div class="grid-container bottom">
                <div class="row">
                    <div class="col-sm-4 left">
                        <?php echo $contentLeft; ?>
                    </div>
                    <div class="col-sm-4 center">
                        <?php echo $contentCenter; ?>
                    </div>
                    <div class="col-sm-4 right">
                        <?php echo $contentRight; ?>
                    </div>
                </div>
            </div>
        <?php endif; ?>
    </div>
<?php endif; ?>

As i noticed myself i have second if / || statement further down, which seems to work fine. It's also not that I mistakenly inserted a wrong type of space or whateever, I have manually rewritten the code multiple times

Aucun commentaire:

Enregistrer un commentaire