Jan Pieter Kunst wrote:[color=blue]
> But I fear that this may be bad OOP style. Or maybe this fear is
> unnecessary. Any insights would be appreciated.
>[/color]
In general, class methods are only accessed statically when they perform
standalone tasks, without references to class instances ($this) or
properties.
An example would be an Utils class, with a method print(). This method would
accept one argument and prints this. Depending on the application you are
building, you can opt for the creation of a class instance or access the
method statically.
In singleton classes (classes which allow only one instance to be created),
an instance is retrieved often through a static method and further
operations are performed through this instance:
$instance =& Singleton::getInstance();
$instance->someMethod();
(the ampersand means that a reference to the class instance is assigned to
the variable; not needed when you have switched over to PHP5)
BTW, the class in your example would not work, because without class
instantiation, only class methods and variables within these methods exist.
You would have to create an instance before you are able to access class
properties:
class SomeClass {
var $var = 'something';
function getSomething($var = 0) {
if ($var === 0) {
if (!isset($this)) $this = new SomeClass;
$var = $this->var;
}
$returnvalue = do_something($var);
return $var;
}
}
See also:
http://www.php.net/manual/en/keyword...ekudotayim.php
JW