Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Others have already answered the question well. I only want to give some other examples, you should be aware of, all are caused by PHP's type juggling. All the following comparisons will return <strong>true</strong>:</p> <ul> <li>'abc' == 0</li> <li>0 == null</li> <li>'' == null</li> <li>1 == '1y?z'</li> </ul> <p>Because i found this behaviour dangerous, i wrote my own equal method and use it in my projects:</p> <pre><code>/** * Checks if two values are equal. In contrast to the == operator, * the values are considered different, if: * - one value is null and the other not, or * - one value is an empty string and the other not * This helps avoid strange behavier with PHP's type juggling, * all these expressions would return true: * 'abc' == 0; 0 == null; '' == null; 1 == '1y?z'; * @param mixed $value1 * @param mixed $value2 * @return boolean True if values are equal, otherwise false. */ function sto_equals($value1, $value2) { // identical in value and type if ($value1 === $value2) $result = true; // one is null, the other not else if (is_null($value1) || is_null($value2)) $result = false; // one is an empty string, the other not else if (($value1 === '') || ($value2 === '')) $result = false; // identical in value and different in type else { $result = ($value1 == $value2); // test for wrong implicit string conversion, when comparing a // string with a numeric type. only accept valid numeric strings. if ($result) { $isNumericType1 = is_int($value1) || is_float($value1); $isNumericType2 = is_int($value2) || is_float($value2); $isStringType1 = is_string($value1); $isStringType2 = is_string($value2); if ($isNumericType1 &amp;&amp; $isStringType2) $result = is_numeric($value2); else if ($isNumericType2 &amp;&amp; $isStringType1) $result = is_numeric($value1); } } return $result; } </code></pre> <p>Hope this helps somebody making his application more solid, the original article can be found here: <a href="http://www.martinstoeckli.ch/php/php.html#equal" rel="nofollow">Equal or not equal</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload