Reply to classes and var declarations

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация