Created
June 23, 2011 09:52
-
-
Save darraghenright/1042270 to your computer and use it in GitHub Desktop.
ZCE Notes - empty()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Signature: empty(mixed $var) | |
* Description: A language construct to check if a *variable* is empty. | |
*/ | |
// The following variables are considered empty: | |
// * false | |
// * NULL | |
// * 0 | |
// * 0.0 | |
// * '' | |
// * array() | |
// * $someClass->declaredPropertyWithNoValue | |
// Usage | |
$thisVarIsEmpty = false; | |
$thisIsAString = 'foo'; | |
empty($thisIsAString); // false! | |
empty($thisVarIsEmpty); // true! | |
empty($thisVarDidNotExistBefore); // true! note... empty does not care if the var did not exist before. | |
// NOTE: empty will not like you if you try | |
// to pass anything other than a var | |
define('SOME_CONSTANT', 1); | |
empty(SOME_CONSTANT); // parse error! | |
empty(array()); // parse error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment