Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Overriding __get() in fActiveRecord

posted by marcus 9 years ago

Hello

Lately I've been overriding fActiveRecords get() function with my own and so far I haven't suffered any ill effects. The full code for my implementation is posted below.

public function __get($var) {
	if (method_exists($this, $var)) {
		return array($this, $var);
	}
	$var = "get".$var;
	$data = $this->$var();
	if (is_string($data))
		return htmlentities($data, ENT_COMPAT, "UTF-8");
	else
		return $data;	
}

If I wrote that correctly it's supposed to catch the times when it's used for callback requests and simply do what fActiveRecord does and otherwise do what I want it to do. I just wanted to make sure it isn't used for something else so I'm not setting myself up for a world of hurt somewhere down the line.

Thanks for an awesome library!

Yes, that should be fine. Flourish uses public members as only callbacks, except for fXML, where it is used to get node and attribute values also. I've been thinking about changing that, but I'm on the fence about the syntax changes.

posted by wbond 9 years ago