EDIT: I just developed what you were trying to ask ... but how good .. will leave my comments anyway. You can replace class and method names with variables if you want .. (but you're crazy) - nick
To call a function from a class, you can do this in one of two ways ...
Or you can instantiate the class and then call it. eg:.
$bla = new Blahh_class(); $bla->do_something();
or ... you can call the function statically, i.e. without a class instance. eg:.
Blahh_class::do_something()
of course you need to declare your function is static:
class Blahh_class { public static function do_something(){ echo 'I am doing something'; } }
If the class is not defined as static, then you must instantiate the object .. (therefore, the object needs a constructor) for example :.
class Blahh_class { $some_value; public function __construct($data) { $this->$some_value = $data; } public function do_something() { echo $this->some_value; } }
It is important to remember that static functions of a class cannot use $this , since there is no instance of the class. (This is one of the reasons they go much faster.)
Bingy Nov 10 '08 at 2:27 2008-11-10 02:27
source share