You are here: Classes without instances « PHP Programming Language « IT news, forums, messages
Classes without instances

Posted by Thomas Mlynarczyk on 11/18/05 09:45

Hi,

In many cases, one needs only a single instance of a class in a script.
Since PHP5 offers class variables like MyClass::$myVar and even class
constants, it seems to me that an instantiation is not needed. Is it
therefore okay and good practise to use a class without instantiation? In
that case I could regard such a class as a collection of functions and
variables that belong together in a way and the prefixed class name could
serve as a kind of namespace identifier:

include "myLib.php"
myLib::$somevar = 'some value';
myLib::somefunc( myLib::MY_CONSTANT );

Another question: In PHP4 I can have

class myLib { function myFunc() { /* do stuff */ } }
myLib::myFunc();

In PHP5, there is the "static" keyword. What exactly is the difference
between

class myLib { public static function myFunc() { /* do stuff */ } }
class myLib { public function myFunc() { /* do stuff */ } }

Greetings,
Thomas

 

Navigation:

[Reply to this 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

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