Skip to content

Instantly share code, notes, and snippets.

@darraghenright
Created June 23, 2011 09:52
Show Gist options
  • Save darraghenright/1042270 to your computer and use it in GitHub Desktop.
Save darraghenright/1042270 to your computer and use it in GitHub Desktop.
ZCE Notes - empty()
<?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