Reply to Re: classes and var declarations

Your name:

Reply:


Posted by Peter Fox on 02/19/06 10:48

Following on from Marcus's message. . .
>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.

There's no gain so avoid the drawbacks.

Drawback 1 : Lack of clarity
var $fooString = ''; // Used to hold results of Foo()
Not only does this tell you in the code what's what but also a
documenter can pick it up.

Drawback 2 : Lack of access modifiers (you'll get these in PHP 5)
private var $bar = 0; // Internal counter

Drawback 3 : Lack of type checking (or something similar in ver 5)

Drawback 4 : Anyone looking at your code will think you're a right
plonker.

Initialising doesn't cost much when compared to the time spent debugging
code. You can start with a null value.

If your class is accumulating loads of unused variables then you
probably want to look again at your class structure or data model.

--
PETER FOX Not the same since the deckchair business folded
peterfox@eminent.demon.co.uk.not.this.bit.no.html
2 Tees Close, Witham, Essex.
Gravity beer in Essex <http://www.eminent.demon.co.uk>

[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

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