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
[Back to original message]
|