|
Posted by Marcus on 02/19/06 03:23
Hello,
I've read many places on the net that when using classes in PHP, all
member variables must be declared via the 'var' keyword.
I know that doing this creates all these variables when the object is
first created.
My question is what is the point of this and is it bad if I don't
declare all my variables at the beginning?
Right now when I have a variable I want to save in the object globally I
just assign $this->variable whenever I need it. I am
serializing/unserializing my object in $_SESSION between page calls.
Everything is working fine, and this is actually better for me, because
I do not want all my variables to be created at the start, but instead
as I go based on different function results (I do not necessarily want
every possible variable in my class to be set on each run).
So to summarize, are there any problems with simply assigning
$this->variable whenever I need, instead of explicitly declaring all
variables with 'var' at the beginning of my class? I have found many
sites telling me I have to declare them, but most don't explain why, and
I have not had any luck finding any documentation on potential drawbacks
with what I am doing.
Thank you all in advance.
[Back to original message]
|