<?=$item ?> or <?php echo $item;?> witch is faster ?

[eluser]Daniel Moore[/eluser]
This is from

Quote:There are four different pairs of opening and closing tags which can be used in PHP. Two of those, <?php ?> and [removed] [removed], are always available. The other two are short tags and ASP style tags, and can be turned on and off from the php.ini configuration file. As such, while some people find short tags and ASP style tags convenient, they are less portable, and generally not recommended.


Also note that if you are embedding PHP within XML or XHTML you will need to use the <?php ?> tags to remain compliant with standards.

As CodeIgniter outputs XHTML, it would be best to stick with <?php ?>, in my opinion. There isn't a great deal of difference between <? ?> and <?php ?>. If you say it makes it easier on designers, I disagree. If I'm working with a designer that can understand <? but not <?php, then I'm already in trouble. At least the <?php tells them that the following is PHP code so they know not to mess with it.

I can explain to a designer in one paragraph how to understand the view files, PHP tags included. Not really a big deal. Whether PHP is allowing it or not isn't the question for me, it's a matter of being compliant to the standard that is being output to the browser.

The only designers I have problems with are the ones that use a graphical HTML editor, which is going to output all kinds of extra garbage that is unwanted anyway, and I avoid those designers at all costs. If I'm unable to locate a designer with the savvy to truly work with HTML (with a text editor), then I'll design the project myself. There have been times when I've just hired a designer to give me a "graphical picture" of how the website should "look" and provide me with the graphics, then I'll do the actual coding to get it there.

In regards to which is faster and slower, if your hosting doesn't have short tags enabled, and you are re-writing the short tags on the fly (Codeigniter has the ability to do this, just enable in the config) then I would imagine it would be considerably slower than the full-tag, simply because it doesn't need to be re-written on the fly (which uses regular expression, eval() and str_replace all together in one, last time I checked.)

Though don't quote me on this, benchmark and the results should speak for itself :-)

[eluser]Daniel Moore[/eluser]
Another thing to think about on this... Not everyone is using CI. If you land a freelancing job installing a 3rd party script on an even different 3rd party server that does not enable short tags, then you'll see why I hate the use of short tags. I have had to work to fix a few other people's non-CI code on several occasions, because they used short tags and it wasn't enabled on a server it needed to be installed on.

I for one don't like to go through every line of code, especially when, in some cases, there are several hundred files and hundreds of thousands of lines of code, just to fix these short tag issues.

I wrote a nifty little PHP script, that when placed in an URL on the server, will search every file in that path, and search all sub-directories as well, locating every PHP file and changing all the short tags to long tags. It handles &lt;?, &lt;?=, <%, and <%= conversion beautifully. It will also check to make sure it doesn't work on itself, and it will also check to make sure it doesn't mess with the Loader.php that comes in the CI Core. (It makes sure a file named "Loader.php" is actually a CI file, though, by looking at the first few lines of the file.)

I don't imagine there are many people that would be interested in such a script, but if you are interested in it, I'll be happy to post it.

[quote author="Atharva" date="1293711620"]Well, it seems from some latest posts that they are not being deprecated which is a good news![/quote]

Not exactly latest news. Smile

Back in April of 2009, from Rasmus:
Quote:...we decided not to remove them in PHP 6

Link: http://marc.info/?l=php-internals&m=123969574312781&w=

[eluser]naiyumie natsume[/eluser]

Hello, I am new to CI and reading the standards because I think compliance to a standard in a framework is important. I am confused though because in the document 'General Style and Syntax' it says that short tags are incorrect to use, and then a couple pages later in 'Alternative PHP Syntax for View Files' it says to use them. Looking closer at the title, I guess this is only intended for Views, but it still seems really inconsistent to me. Also, in the style document it says not to use || for logical or but to use OR (because it may appear as the number 11?) and not to use AND but to use &&. Is that really practiced? That seems pretty absurd to me. And I prefer standardized, structured coding so I'm not just being difficult here.

Can someone save me a little time sifting through source files and let me know how these short tags and logical operators are really used in practice within this framework?


They say not to use the &lt;?= ?&gt; because some servers will not allow them, also it interferes with xml tags.
I stick to useing &lt;?php echo :?&gt; etc.

As far as the User guide is in correct in some ways, AND and && are not the same, it depends on what you are evaluating! Same thing with the other operators. Here you will have to use your own judgement.

But outside of that I stick to the style guidelines.


[eluser]Daniel Moore[/eluser]
The only difference between AND and && is operator precedence. It will evaluate the same, but not necessarily in the same order when evaluating a larger expression. && has a higher precedence than AND.

Since I always use parentheses to make order of evaluation clear (which also improves readability), it is not an issue for me. I always stick to OR and AND both, simply because they are faster to type (for me, being a touch typist.)

&& has a higher precedence, followed by ||, then followed by the ternary operator, then followed by the assignment operators, then followed by AND then OR. So the real question is, do you need your AND or && evaluated before or after an assignment operator or ternary operator is evaluated? To me, it is simply too much to keep up with remembering OR is evaluated after ternary and assignments and && before, which can lead to mistakes in coding. In my book, if you're going to use &&, then use ||, and if you're going to use OR, then use AND. It's makes for more consistent and easier to read code overall. This is one area I disagree strongly with the code style guideline for CodeIgniter. I prefer to use logical readability for my guideline as how to code.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.