niusernamey18
New Member
Wondering if it's possible to do something like the following (I know the code won't work as intended, just trying to get the purpose across):\[code\]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]; }};\[/code\]I want to be able to set a variable like:\[code\]$form->Values['whatever'] = 'dirty';\[/code\]and have it run through the setter function which would call some cleaning operations and actually end up filling a couple other arrays like 'HtmlValues' and 'SqlValues' so I can just pull the values encoded for the format I want, so I can later call\[code\]echo $form->HtmlValues['whatever'];\[/code\]The problem is of course the normal issue that if you just use _get, you get end up setting a value that's returned, and even though &_get returns it by reference and thing kind of work, __set is never actually called, even though you're setting a private member.So basically, I'm wondering if there's a way to call a function on a value whenever you set it within an array (potentially multiple arrays deep and what not like \[code\]$form->Values['group']['item'] = 'whatever';\[/code\]The desired output would be something like:\[code\]$form->Values['name'] = "&";echo $form->HtmlValues['name']; = &\[/code\](Just to reinforce, I'm not looking for the actual encoding, just the ability to call it on every variable as it's set/changed without having to encode the entire array manually)