Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixture of php shorttags

I'm taking over a codeigniter project and notice the original dev uses a mixture of short tag and php tags in the views. For example:

<div id="content">

        <?=show_header()?>

        <ul id="products">
            <?php if (count($products) > 0) : ?>
            <?php foreach($products as $product) : ?>
             ...
</div>

Is this bad practice to inherit? I think it is already causing me problems in my dev environment.

EDIT: What about <?= => tags INSIDE <? php ?> tags on some views? Like this:

<ul>
<?php foreach ($details as $detail) : ?>
<?php $detail = split(',',$detail); ?>
<?php if ($detail[0] != '') : ?>
    <li>
    <strong><?=ucwords($detail[0])?></strong> : <?=$detail[1]?>
    </li>
<?php endif; ?>
<?php $i++; ?>
<?php endforeach; ?>
</ul>

This is whats confusing me right now.

like image 940
ItsPronounced Avatar asked Jan 27 '26 01:01

ItsPronounced


1 Answers

Bad idea. Not all installations and versions of PHP support this type of tagging, and it makes the code very hard to read.

My advice is: always use the full open-close tags: <?php /*...*/ ?>.

If I had been given your script to work with or fix, I would have stopped at line 3, cursed and scratched my head, because that is plainly unreadable.

Also, at line 6 & 7, I'd rather use { instead of :, also for readability.

like image 191
Emil Avatar answered Jan 28 '26 13:01

Emil