I wonder if it is possible to do something like the following (I know that the code will not work as intended, just trying to achieve the goal):
class Form
{
private $v = array();
function __set($varName, $varValue)
{
... do some treatment on the varValue ...
$this->v[$varName] = $varValue;
}
function &__get($varName)
{
if(!isset($this->v[$varName]))
$this->v[$varName] = NULL;
return $this->v[$varName];
}
};
I want to be able to set a variable like:
$form->Values['whatever'] = 'dirty';
and skip through the setter function, which will invoke some cleanup operations and actually finish filling out a couple of other arrays such as “HtmlValues” and “SqlValues”, so I can just pull out the values encoded for the format I want, so I can call later
echo $form->HtmlValues['whatever'];
The problem is, of course, the usual problem: if you just use _get, you end up setting the return value, and even if & _get returns it by reference and subject work, __set is never called, even if you set a private member.
, , , , (, $form->Values['group']['item'] = 'whatever';
:
$form->Values['name'] = "&";
echo $form->HtmlValues['name']; = &
( , , , / )