PHP: Universal NULL Object
When working with interfaces you sometimes need a object as parameter. Thats why i wrote this primity universal null object that does nothing at all and does not throw any errors:
<?php
/**
* Universal NULL object.
*
* Will throw no error messages so can be used as universal parameter.
* Does overwrite all available magic methods used in PHP5.3.
*
* @author Julius Beckmann
*/
class NullObject {
public function __construct() {}
public function __destruct() {}
public function __set($name, $value) {}
public function __get($name) { return null; }
public function __isset($name) { return false; }
public function __unset($name) {}
public function __call($name, $args) {}
public function __toString() { return ''; }
public function __invoke() {}
public function __clone() {}
public static function __callStatic($name, $args) {}
}
/**
* Universal NULL object.
*
* Will throw no error messages so can be used as universal parameter.
* Does overwrite all available magic methods used in PHP5.3.
*
* @author Julius Beckmann
*/
class NullObject {
public function __construct() {}
public function __destruct() {}
public function __set($name, $value) {}
public function __get($name) { return null; }
public function __isset($name) { return false; }
public function __unset($name) {}
public function __call($name, $args) {}
public function __toString() { return ''; }
public function __invoke() {}
public function __clone() {}
public static function __callStatic($name, $args) {}
}
GistHub:
https://gist.github.com/1101526
No related posts.