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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With