I think there is no style for the short echo tag yet. Before 5.4 it was almost forbidden to use it, by guru of the code . I’ve rechecked all main codestyles and there is no any info for this, only questions in some discussions without unswers yet. So if it will be very popular and frequently asked, then maybe new rule will be added to code styles for this tag. In the oficial documentation we can see an example of this tag without any spaces at all.
PHP Tag <?php usually is on the separate line, so in theory it’s also possible for this <?= tag
<?=
Yii::$app->charset;
?>
*looks ugly I think)
I’m agree with you that version <?=Yii::$app->charset; ?> looks inconsistent and maybe version <?= Yii::$app->charset; ?> should be more correct. But lets see what the community will say. We are witnesses of the new era changes
If there are no good reasons to remove this space, I vote for keeping it, because <?=Yii: (nine strange symbols in a row) looks like black magic spell to me
Using short tags per se is not good practice. Firstly it is discouraged on the PHP site. Secondly, it can be turned off in the PHP ini file. Thirdly, the PHP version must be compiled with the short tag option.
Therefore, if a script with short tags is used on a site with the short tags not enabled in the config, or compiled into the interpreter, the script will fail.
Great, now looks better. Thanks yii team for the quick and clean solution. But it still like ‘home made’ style(though maybe the most correct one), I think we should see psr-N soon:-)
So by default is Yii2 going to use the short echo syntax?
In all honestly I actually prefer the full syntax:
<?php echo $i; ?>
instead of (proposed):
<?= $i ?>
The full syntax just seems to makes more sense, if you get what I mean. It kind of encourages the notion of "doing things properly" - which is what Yii is all about.
I use full PHP tags everywhere and have been doing so ever since I started using Yii.
For example for me it doesn’t matter. I prefer to use standards in such situations, but there is no many info for this particular moment yet. But my thoughts are - if PHP 5.4 encourages to use this short code way, then it means something (for example that PHP community or at list Rasmus Lerdorf likes it))
This thread is all about discussion of the new requirement. Now Yii2 requires php5.4 as a minimum version, so the short code is one of the features that php5.4 encourages to use.
That’s fine, expect my main concern is regarding consistency.
Full PHP tags will still need to be used to create sections of PHP code or variables. The only time where the short syntax will be used is when echoing out variables.
I think you can use the full version of the tag if you prefer . The most important differents is that it’s not a PHP tag (I mean PHP tags that show begin and end of the php code), its a short echo version. Previously this short echo version was a bad practice becouse it could be blocked with the same config option (if short PHP tags were disabled). Short PHP tags still is a bad practice, and they were flagged bad in coding standards not becouse it’s not beautiful to have full and short versions of the PHP tags in the same file, but due to some issues of the code with the short PHP tags. Now the short echo version works always and it requires some time before it will be reflected in the coding standards, but I have a feeling that it will be rather sooner than later (because we will see a lot of different views before this moment will have a standard).