Add more values to AR private $_attributes

Hi folks,

Have you ever try to add more values to AR "private $_attributes" on a specific model?

I need to add more values ($key => $value) on this array, but it’s a private array, so i’d like know if there are some method to do it?


Could you give me a code snipe ?


Sorry but I don’t have a code snipe, but my idea is like a array merge, I know that the AR $_attributes is an array, so I’d like know if there are some way to add more values to it.

For example, I have a model that extends AR class and in this model there are an array with some values (key => value).

My idea is use some thing like CMap::mergeArray to merge this array to $_attributes array.


To more clarify a little, my idea is pass a array to AR $_attributes, to use the key => values like AR attributes. eg:

if my array is array(‘car’ => ‘bmw’, ‘year’ => ‘2011’), I’d like to use it on this way $model->car and $model->year


Frankly: I have big question marks over my head, when i read your question. Why you want to do this? If you fiddle around with the internals of AR, you shouldn’t wonder if your DB operations will not work correctly anymore afterwards.

Why don’t you just add public properties to your AR model? You could also create a subclass and override __get()/__set() there, but this again is a more dangerous approach. But by no means i would try to touch the private properties, because that’s why they where made private in the first place (OOP encapsulation).