<?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>Tue, 21 May 2013 15:13:01 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Greg Beaver's Blog: comparing strings in PHP with the == operator]]></title>
      <guid>http://www.phpdeveloper.org/news/4511</guid>
      <link>http://www.phpdeveloper.org/news/4511</link>
      <description><![CDATA[On <i>Greg Beaver</i>'s blog today, there's <a href="http://greg.chiaraquartet.net/archives/105-comparing-strings-in-PHP-with-the-operator.html">his look</a> at string comparison with the "equals equals" (==) operator in PHP and some issues he found around it.
<p>
<quote>
<i>
Recently, an obscure detail in the way PHP processes strings came to my attention in the form of an endless loop occasionally found in phpDocumentor's parsing of a file. 
<p>
This is processed by code that checks for simple lists (like 1. blah 2. blah, or - blah - blah, etc.). However, an innocent call to in_array($x, array('1.', '0.')) had surprising and unexpected results: our friendly PHP determined that '01' was in the array('1.', '0.')!! This is of course patently false, and made little to no sense until I realized that unlike my previous understanding (when comparing an integer to a string, the string is converted to an integer), PHP actually converts all numeric-like strings into integers when comparing them.
</i>
</quote>
<p>
To help avoid these kinds of situations repeating themselves, he makes a few suggestions when comparing your values: "use === instead of ==", "use the third parameter in in_array, set to true", and "use strcmp() or one of its cousins". In <a href="http://greg.chiaraquartet.net/archives/105-comparing-strings-in-PHP-with-the-operator.html">his opinion</a>, though, this kind of auto-conversion is a bit dangerous - bit it's all about perspective...]]></description>
      <pubDate>Fri, 16 Dec 2005 07:11:30 -0600</pubDate>
    </item>
  </channel>
</rss>
