Oscar Arreyano wrote:
Quote:
"FutureShock" <futureshockx@att.netwrote in message
news:GDVCk.1776$c45.424@nlpi065.nbdc.sbc.com...
Quote:
>tjboudreaux wrote:
Quote:
>>Hi,
>>>
>>This might be a crazy question, but does anyone know how to add
>>variables dynamically to a class. Here's what I want to do.
>>>
>>I have a class Model, which I inherit for interfacing with database
>>tables, much like a classic MVC pattern. I want to be able dynamically
>>create a variable for each field in that table. This is sort of what I
>>tried out
http://pastebin.com/m3fed09a8
>>>
>>>
>>I just need to know if there is a way to do what is on lines 8 - 10,
>>and how that can be done.
>>>
>>Thanks
>>>
>>>
>>Travis
>Take a look at overloading using the __get and __set methods.
>>
>
http://www.php.net/manual/en/languag...verloading.php >
The overload will do no good as both __get and __set are ONLY called when a
NON-existing interface (property, function, etc.) is referenced by a caller.
>
To the op...why not use an array whose keys are the field names? Is there
some kind of validation you are going for if a caller changes a value? If
not, an array is the easiest to implement.
>
>
Yes you are right, I think an Array would be the better way, I had not
thought of that. He can assemble his list or variables, send them in one
lump sum and extract them in the class. I may have to play around with
that idea for a bit, may come in useful sometime.
Scotty