Reputation: 8668
Just wondering, I have a codeigniter project that I have been asked to do some work on. Im also trying to (where I can) prepare the project for upgrading to php 7.x (currently on 5).
One thing Im confused about is the use of php short tags. I love them but it seems they are being removed in 7?
So my question is, should I be removing them? The problem is, they make the code so much more readable, why are they removing it?
So for example:
<?php if ($product->price_discounted > 0)
{
echo "<p class='discounted price'>" . $product->price_discounted . "</p>"
}
?>
vs
<? if ($product->price_discounted > 0): ?>
<p class='discounted price'><?= $product->price_discounted ?></p>
<? endif; ?>
I would much rather the second version, but whenever I run my project on php7 these don't work. Am I missing something or are they really removed?
FYI: I have short tags on in php.ini
Upvotes: 5
Views: 10933
Reputation: 2860
Short tags are not deprecated anymore. Despite the RFC passing, some controversy ensued and the PHP internals group refused to implement it1. Check out the migration guide for confirmation:
https://www.php.net/manual/en/migration74.php
Short open tags are deprecated in PHP 7.4, and will be removed in PHP 8.
https://wiki.php.net/rfc/deprecate_php_short_tags
Also, the short echo (<?=
) is not part of short_open_tag
as of 5.4. It is always available, and is not part of the deprecation.
https://wiki.php.net/rfc/shortags
Upvotes: 12
Reputation: 79
Is the correct php.ini being loaded?
<?php phpinfo(); ?>
Check for Loaded Configuration File
Upvotes: 1
Reputation: 1354
Shorthand tags are still in PHP7, the tags being removed are:
<% opening tag
<%= opening tag with echo
%> closing tag
(<script\s+language\s*=\s*(php|"php"|'php')\s*>)i opening tag
(</script>)i closing tag
https://wiki.php.net/rfc/remove_alternative_php_tags
Upvotes: 6