I got this exception: "indirect modification of overloaded property"
when I tried this:
$this->models[$class]->attributes = <some array returned from function>;
Note: The above code worked perfectly. Although I moved the $models property inside a Behavior
After googling I think the problem is that I am referring to a property as an array while the property does not exist (this is true, it should not exist, now is part of the behavior)
I temporarily solved the problem using this code:
$models = $this->models;
$models[$class]->attributes = <some array returned from function>;
$model->models = $models;
Note: Yes indeed I have implemented the __get and __set php special methods inside the behavior. I am not exactly sure if using __get and __set methods inside a behavior is a neat implementation. Please tell me if this hides problematic issues
This used to be a php bug as I see in other forums (other websites)
So is there a way to solve the above problem without changing the code in every class that uses this behavior?
The same error message happened to me when I was trying to set the CActiveRecord Attributes array.
So I discovered another method to overcome this issue, in a case where the magic method is related to an object variable which contains an array take a look: you create an AUXILIARY ARRAY in which you put the original and the new values (sometimes one wants to REPLACE a value related to one of the keys, and these methods are not satisfactory). And AFTERWARDS use an assignation, which works like the reference. For example, in the next example, I generalize $model->attribute to
"Object->array_built_with_magic", but I used it first with $model->attribute. Take a look:
$auxiliary_array = array();
foreach(Object->array_built_with_magic as $key=>$value) {