PHP Classes

File: zray/vendor/PHP_CodeSniffer-2.2.0/CodeSniffer/Standards/CodeIgniter/Docs/Operators/StrictComparisonOperatorStandard.xml

Recommend this page to a friend!
  Classes of Simo   CodeIgniter Plugin for Z-Ray   zray/vendor/PHP_CodeSniffer-2.2.0/CodeSniffer/Standards/CodeIgniter/Docs/Operators/StrictComparisonOperatorStandard.xml   Download  
File: zray/vendor/PHP_CodeSniffer-2.2.0/CodeSniffer/Standards/CodeIgniter/Docs/Operators/StrictComparisonOperatorStandard.xml
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: CodeIgniter Plugin for Z-Ray
Show CodeIgniter application information in Z-Ray
Author: By
Last change:
Date: 2 years ago
Size: 1,305 bytes
 

Contents

Class file image Download
<documentation title="Strict comparison operators"> <standard> <![CDATA[ Some PHP functions return FALSE on failure, but may also have a valid return value of "" or 0, which would evaluate to FALSE in loose comparisons. Be explicit by comparing the variable type when using these return values in conditionals to ensure the return value is indeed what you expect, and not a value that has an equivalent loose-type evaluation. Use the same stringency in returning and checking your own variables. Use === and !== as necessary. ]]> </standard> <code_comparison> <code title="Valid strict comparison"> <![CDATA[ if (strpos($str, 'foo') === FALSE) { echo 'Do something.'; } function build_string($str = "") { if ($str === "") { echo 'Buid string.'; } } ]]> </code> <code title="Invalid loose comparison"> <![CDATA[ // If 'foo' is at the beginning of the string, strpos will return a 0, // resulting in this conditional evaluating as TRUE if (strpos($str, 'foo') == FALSE) { echo 'Do something.'; } function build_string($str = "") { if ($str == "") { // uh-oh! What if FALSE or the integer 0 is passed as an argument? echo 'Buid string.'; } } ]]> </code> </code_comparison> </documentation>