Created
November 25, 2013 07:26
-
-
Save aanton/7637573 to your computer and use it in GitHub Desktop.
Null PHP Class
This file contains hidden or 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 | |
class Null | |
{ | |
private static $instance; | |
public function __call($name, $arguments) | |
{ | |
if (strpos($name, 'is') === 0 || strpos($name, 'has') === 0) | |
{ | |
return false; | |
} | |
else | |
{ | |
return self::getInstance(); | |
} | |
} | |
function __toString() | |
{ | |
return ''; | |
} | |
public static function getInstance() | |
{ | |
if (!self::$instance) | |
{ | |
self::$instance = new Null(); | |
} | |
return self::$instance; | |
} | |
} | |
/* Demo */ | |
$null = Null::getInstance(); | |
var_dump($null->isActive()); | |
var_dump($null->hasImage()); | |
var_dump($null->getImage()); | |
var_dump($null->getImage()->getChildImage()); | |
var_dump($null->getImage()->getChildImage()->isActive()); | |
echo $null->isActive() . "\n"; | |
echo $null->hasImage() . "\n"; | |
echo $null->getImage() . "\n"; | |
echo $null->getImage()->getChildImage() . "\n"; | |
echo $null->getImage()->getChildImage()->isActive() . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment