Skip to content

Instantly share code, notes, and snippets.

@cebe
Created August 9, 2012 21:27
Show Gist options
  • Select an option

  • Save cebe/3308196 to your computer and use it in GitHub Desktop.

Select an option

Save cebe/3308196 to your computer and use it in GitHub Desktop.
PHP empty($x) vs. $x===''
<?php
$t = microtime(true);
for($n=0; $n<10000000; $n++) {
if (empty($class)) {
}
}
$e = microtime(true) - $t;
echo $e . "\n";
$class='';
$t = microtime(true);
for($n=0; $n<10000000; $n++) {
if ($class==='') {
}
}
$e = microtime(true) - $t;
echo $e . "\n";
@cebe
Copy link
Author

cebe commented Aug 9, 2012

Actual result is that empty is slightly faster plus allows me to have $class variable undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment