Dynamically Add Properties To Ccomponent Based Object

Normally I would do the following:




public function addProperty($newPropertyName, $value) {

        $this->$newPropertyName = $value;

    }



But my Foo class extends the CComponent so the magic __set and __get are overrided.

How can I add new property dynamically from within the Foo class?

http://www.yiiframework.com/doc/api/1.1/CComponent

Also :

http://www.yiiframework.com/wiki/167/understanding-virtual-attributes-and-get-set-methods/#hh3

I aw aware of "black" magic of the __set and __get methods but thanks for notice.

The solution with setProperty() and getProperty() methods won’t allow me to do it dynamically right? I have to define those methods in class so there’s no dynamic. The problem is my FooForm class will have few attributes that I’m not aware of at the class creation time. That’s why I need to dynamically add the properties.

Well, I’m not sure of you’re trying to do, but you’re trying to do something like :




$foo->bar = "fooBar"; 

even if $bar is not defined in Foo, or if there is no method getBar() in Foo.

Well, your trying to implement some registry pattern right ?

Have a look here :

http://www.yiiframework.com/forum/index.php/topic/3506-yii-registry/

— EDIT —

Still not sure, but in first link I provide you :

http://www.yiiframework.com/wiki/167/understanding-virtual-attributes-and-get-set-methods/