<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Wed, 22 May 2013 05:47:30 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Fabien Potencier's Blog: The PHP Ternary Operator: Fast or not?]]></title>
      <guid>http://www.phpdeveloper.org/news/16601</guid>
      <link>http://www.phpdeveloper.org/news/16601</link>
      <description><![CDATA[<p>
In a new post <i>Fabien Potencier</i> looks at <a href="http://fabien.potencier.org/article/48/the-php-ternary-operator-fast-or-not">the ternary operator</a> in PHP and wonders which is faster - using it or not (well, sort of...)
</p>
<blockquote>
People like micro-optimizations. They are easy to understand, easy to apply... and useless. But some time ago, while reviewing pull requests for <a href="http://twig-project.org/">Twig</a>, I read an interesting discussion about the performance of the <a href="https://github.com/fabpot/Twig/issues/380">ternary operator</a> in PHP (thanks to <a href="https://github.com/nikic">@nikic</a> for the investigation). Do you know which [example] snippet is the fastest (of course, they do exactly the same)? The right answer is: it depends.
</blockquote>
<p>
He notes that it's all about the data being worked with. As some of his tests show (testing code included) there does end up being a difference between using it on a small and large dataset. After investigation, it was found that the ternary operator copies (copy-on-write) the value versus an "if" that just evaluates. He also mentions the new "?" version of the ternary syntax in PHP 5.3, but notes it still suffers from the same issue.
</p>
]]></description>
      <pubDate>Mon, 18 Jul 2011 10:35:36 -0500</pubDate>
    </item>
  </channel>
</rss>
