Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Object Filter

DZone's Guide to

Object Filter

·
Free Resource

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com

class ObjectFilter{
	protected $o;
	protected $filter;

	public function __construct($o, $filter){
		$this->o = $o;
		$this->filter = is_array($filter) ? $filter : array($filter);
	}
	public function __get($n){
		$s = $this->o->$n;
		foreach($this->filter as $f)
			$s = call_user_func($f, $s);
		return $s;
	}
	public function __set($n, $v){
		return $this->o->$n = $v;
	}
	public function __call($n, $a){
		return call_user_func_array(array($this->o, $n), $a);
	}
	public function getObject(){
		return $this->o;
	}
}


Example


$o = new ObjectFilter(new stdClass, 'strip_tags');
$o->blabla = 'lala';
echo $o->blabla;
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}