Ok, so talking about best practices and my first time to use Yii actually but the first thing I noticed is that why is Yii still using something like <?=‘HELLO’?> which is no longer recommended rather than <?php echo ‘HELLO’?> ?
Ok, so talking about best practices and my first time to use Yii actually but the first thing I noticed is that why is Yii still using something like <?=‘HELLO’?> which is no longer recommended rather than <?php echo ‘HELLO’?> ?
Where did you get this "no longer recommended" thing? In fact since 5.4 <?= is always valid regardless of configuration.
PHP also allows for short open tag <? (which is discouraged since it is only available if enabled using the short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option).
Not true anymore. Since PHP 5.4.0, <?= is always available. Yii 2 requires 5.4.0
http://docs.php.net/manual/en/ini.core.php#ini.short-open-tag
Ok, agree. Nevertheless it’s better to use <?php ?> as independent from configuration.
Only if you work in old PHP environment. Or if you are afraid that this will change in future version. But in this case you should use array() instead of [] as well. For the same reason.
If you’re using a framework that requires php 5.4+ then you should write your php in php 5.4+. It is best practice to write in what you are using.
Yii2 requires PHP 5.4, no getting around that, unless you want to find every short tag and change them yourself. Aside from the short tags, you have the new use of arrays, that you would then have to go fix. Long story short, it just wont work on anything less than 5.4.
Since 5.4, the short tags are default and enabled from the start.
There is no real drawback to using the short hand version compared to the original.
So just suck it up and accept it, along with the new arrays.
I never really used the new short tag prior to Yii2, though I was aware of them. I worked with many different systems, and backwards compatibility was something to think about.
When you are not in Yii or a modern framework that supports them, and you see the code is old, just follow suit. If the client moves to another server that isn’t 5.4 or higher, you don’t want your code the reason why it throws errors. So when your in there, just look at the code. If you see the new array notation, or the new php short open tags, then go ahead and enjoy yourself… If not, then use the old just to be safe.