View Full Version : Another totally irrelevant q: Which is faster? <?=$string?> or <?php echo $string; ?>
grabmail 03-02-2006, 11:38 AM Yes. I know <?=$string?> is not advised during to conflicts with XML.
I just want to know which is faster of the 2 and y?
Just curious about how PHP parse the 2 methods and the overhead involved.
Korvan 03-02-2006, 12:01 PM The overhead for the echo itself is much greater than the php parser overhead to run that script. Output functions i find are relitively slow themselves compared to any other process. In strict terms, <?= should never be used anyway.
grabmail 03-02-2006, 12:43 PM so which is faster?
<?=
or
<?php echo
azizny 03-02-2006, 01:23 PM <?php
if($something){ echo trim(strtolower(strtoupper($something)));}
?>
This should be fast, but seriously whats up with these really crazy questions lately?
:D
Peace,
grabmail 03-02-2006, 01:49 PM i just want to know how PHP parse the various functions.
Like before the others told me, I've always thought that true/false is faster than 1/0 since the PHP website always use it.
Now, i know they use it for readibility issues. Fair enough. That's good to know.
So now, i want to know which of the 2 echo methods is faster and why.
laserlight 03-02-2006, 02:23 PM Why dont you test it yourself and find out?
deuce868 03-02-2006, 03:17 PM I tell you what, if the short tags are turned off in the php.ini it's going to be a LOT faster...as it never parses. :)
compjab 03-02-2006, 07:59 PM The overhead for the echo itself is much greater than the php parser overhead to run that script. Output functions i find are relitively slow themselves compared to any other process. In strict terms, <?= should never be used anyway.
Why should one not use <?=
deuce868 03-02-2006, 08:04 PM Because not all servers have it enabled and there is talk that it will be defaulted to off in future versions of PHP.
compjab 03-02-2006, 08:05 PM Because not all servers have it enabled and there is talk that it will be defaulted to off in future versions of PHP.
What should be used instead?
What should be used instead?
<?php
// your code
?>
This form is always enabled and also causes no incompatiblity with possible XML tags.
If you are not using <?xml ?> and have control over short_open_tag (http://www.php.net/manual/en/ini.core.php#ini.short-open-tag) it shouldnt matter however.
arkin 03-02-2006, 08:56 PM I do frequently use <?=. It comes handy in alot of situations regarding my code.
If my company were to upgrade PHP and this was defaulted to off I would expect them to email me beforehand to warn me. Its a simple replace <?= with <?php echo.
In my opinion, I don't think either are faster because they are both the same function (i think?).
grabmail 03-03-2006, 02:38 AM you know why i like <?= ?
Because it's good for php-ignorant designers who work on the templates
They don't need to type <?php echo $body ?>
They just need to type <?=$body?>, which is similar to the {$body} format that most template engine use.
So it's easier for them. But i personally won't use it since it's deprecated.
dexxtreme 03-03-2006, 04:15 AM I do frequently use <?=. It comes handy in alot of situations regarding my code.
If my company were to upgrade PHP and this was defaulted to off I would expect them to email me beforehand to warn me. Its a simple replace <?= with <?php echo.
In my opinion, I don't think either are faster because they are both the same function (i think?).
The problem is that most hosting companies won't know every single issue that may come up with every single PHP script when upgrading PHP to a newer version. Reading through the Changelogs (and associated bug reports) for new versions of PHP is usually an annoyingly long process. Oftentimes there are not enough time or resources (nor would it be practical) to do full regression testing to verify what miscellaneous settings are no longer set as default and what has to be reconfigured before going into production. They might notify you when they upgrade to a newer version, however if they are forced to upgrade due to a major security risk to the server then you may not get enough time to modify your scripts. For example, Squirrelmail recently went through a period when there were miscellaneous incompatibilities with particular versions of PHP, but only when displaying certain types of emails. Those issues didn't show up until after people had upgraded PHP to newer versions. It would not be possible to account for that beforehand without being fully versed on the internals of both PHP and Squirrelmail.
But i personally won't use it since it's deprecated.
Its not really deprecated, it just doesnt work that well with XML
From http://www.php.net/manual/en/ini.core.php#ini.short-open-tag
Tells whether the short form (<? ?>) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"'; ?>. Also if disabled, you must use the long form of the PHP open tag (<?php ?>).
srcnix 03-03-2006, 08:22 AM This thread isn't pointless, you're learning from it and others will learn from it.
JustinH 03-03-2006, 02:08 PM Long tags took: 0.798220872879 seconds.
Short tags took: 1.64670300484 seconds.
100,000 iterations. You should really try doing your own tests for this type of stuff, although I still fail to see the point in it. Sacraficing readability of funtionality for the purpose of saving milliseconds is silly.
|