<?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 20:18:20 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[PHP Tip-a-Day: PHP Tutorial: Convoluted Code - Combining Ternary Operators and Anonymous Functions]]></title>
      <guid>http://www.phpdeveloper.org/news/18023</guid>
      <link>http://www.phpdeveloper.org/news/18023</link>
      <description><![CDATA[<p>
On the PHP Tip-a-Day site <i>Greg Bulmash</i> shares a bit of "convoluted code" that could potentially cause confusion in the future maintenance of your application - <a href="http://www.php-tip-a-day.com/php-tutorial-convoluted-code-combining-ternary-operators-and-anonymous-functions/">combining ternary with anonymous functions</a>.
</p>
<blockquote>
Following on yesterday's post about chaining if statements without brackets on a single line, I tried to explore other ways to perform this "test if the variable is set, then do a comparison if it is" logic. I created one of the most convoluted lines of code I've ever written. It's no SQL join that spans 5 whiteboards, but it's pretty unreadable.
</blockquote>
<p>
His example uses not just one ternary comparison, but nested ones with the anonymous function as the first condition. He points out that, if you're not careful with this method and make both sides anonymous functions, you could be in for a "cannot be converted to string" error on the closure side. 
</p>
<blockquote>
I'm sure there might be a very good reason to put two anonymous functions in a ternary operator, but I can't think of one at the moment. It's a fairly ugly proposition.
</blockquote>]]></description>
      <pubDate>Wed, 30 May 2012 10:09:40 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPMaster.com: Using the Ternary Operator]]></title>
      <guid>http://www.phpdeveloper.org/news/17068</guid>
      <link>http://www.phpdeveloper.org/news/17068</link>
      <description><![CDATA[<p>
On PHPMaster.com today there's a new tutorial showing the use of a sometimes overlooked (but very handy) alternate syntax that PHP includes - the <a href="http://phpmaster.com/using-the-ternary-operator/">ternary operator</a>, a short-hand if/else.
</p>
<blockquote>
You're probably already familiar with PHP's if statement. It's very similar to its counterparts in many other programming languages and represents one of the most fundamental concepts in programming. [...] But there's a way to build on this concept and increase your $coolFactor a bit in the process. Allow me to introduce you to the ternary operator, which serves as a shorthand notation for if statements.
</blockquote>
<p>
They introduce the ternary operator's syntax, the ":" and "?" operators and includes a few pieces of code showing its use. Thankfully they also include a warning - don't overuse or abuse it...and especially don't nest them - that just leads to headaches.
</p>]]></description>
      <pubDate>Tue, 01 Nov 2011 09:43:35 -0500</pubDate>
    </item>
    <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>
    <item>
      <title><![CDATA[Erling Alf Ellingsen's Blog: PHP Must Die]]></title>
      <guid>http://www.phpdeveloper.org/news/13816</guid>
      <link>http://www.phpdeveloper.org/news/13816</link>
      <description><![CDATA[<p>
In a <a href="http://www.steike.com/code/php-must-die/">(slightly inflammatory) post</a> to his blog today <i>Erling Alf Ellingsen</i> shares why he thinks that "PHP must die", mostly due to some of the inconsistencies his has with other languages.
</p>
<p>His examples include:</p>
<ul>
<li>String vs. numeric handling 
<li>That PHP supports octal numbers "by accident"
<li>A lexer bug with hex values
<li>A parser bug involving the ternary operator
</ul>
<p>
<a href="http://www.steike.com/code/php-must-die/#comments">Comments</a> on the post include those supporting the "die" opinion - that PHP just doesn't have it together like other languages - and those taking a bit more balanced approach on PHP's strengths and weaknesses.
</p>]]></description>
      <pubDate>Mon, 11 Jan 2010 13:49:41 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Ask About PHP: PHP's alternative syntax and why it's useful]]></title>
      <guid>http://www.phpdeveloper.org/news/12353</guid>
      <link>http://www.phpdeveloper.org/news/12353</link>
      <description><![CDATA[<p>
On the "Ask About PHP" blog today there's <a href="http://www.askaboutphp.com/beginners/59/phps-alternative-syntax-and-why-its-useful.html">a new post</a> looking at some of the alternative syntaxes that PHP has to offer for control structures.
</p>
<blockquote>
PHP offers an alternative way to write their control structures for as long as I've remembered. It basically does away with the curly brackets and replaces the opening curly with a colon (:) and the closing with '˜end'-whatever. I have to be honest and say I've never really found a need to use the alternative syntax, simply because I'm so used to using the curly braces after so many years of using PHP. Plus, it's less typing!
</blockquote>
<p>
The one specifically mentioned deals with "if" evaluations. There's two other options to the usual braces method - one being a shorthand using colons and a semicolon and the other using the <a href="http://php.net/ternary">ternary syntax</a>.
</p>]]></description>
      <pubDate>Thu, 16 Apr 2009 07:50:56 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[PHPBuilder.com: The Ternary Conditional Operator]]></title>
      <guid>http://www.phpdeveloper.org/news/9760</guid>
      <link>http://www.phpdeveloper.org/news/9760</link>
      <description><![CDATA[<p>
The PHPBuilder.com site has a <a href="http://www.phpbuilder.com/columns/scross99_20080305.php3">quick reminder</a> about a handy little bit of functionality PHP has to make evaluations quicker - the ternary operator.
</p>
<blockquote>
This allows you to check for the existence of a variable (or check that the variable has a valid value) and assign a value accordingly. This is very useful when you are dealing with $_GET, $_POST, $_SESSION etc. variables, because you don't know whether the incoming variable will exist, and if it doesn't you might want to assign a default value. 
</blockquote>
<p>
An example is included and explained - evaluating an index in the _GET superglobal to see if it exists. It returns either the value itself or a false.
</p>]]></description>
      <pubDate>Fri, 07 Mar 2008 12:04:00 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[WebReference.com: Unary, Binary, and Ternary Operators in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/8136</guid>
      <link>http://www.phpdeveloper.org/news/8136</link>
      <description><![CDATA[<p>
WebReference.com has a <a href="http://www.webreference.com/programming/php_operators/">new tutorial</a> that looks at the difference sorts of operators that PHP has to offer - unary, binary and ternary - to help you with the logic in your applications.
</p>
<blockquote>
An operator is a special character or combination of characters that operates on variables.  There are 3 types of operators in PHP: unary, binary and ternary. They can be used to manipulate a variable with up to 3 arguments at a time.  This article wasn't written to discuss the meaning and usage of each operator in PHP, but rather to explain the differences between these types of operators and to give examples about how each functions.
</blockquote>
<p>
They look at the <a href="http://www.webreference.com/programming/php_operators/">different types of operators</a> (and include examples for each) - unary (like ! or ++), binary (things like + / == and &&) and a special case - ternary. This uses two characters in conjunction (the question mark and colon) to replace a simple sort of If statement.
</p>]]></description>
      <pubDate>Wed, 27 Jun 2007 14:51:46 -0500</pubDate>
    </item>
  </channel>
</rss>
