If I write a public static method in a class ie…
public static function get_info($type){
switch($type){
case'title':
self::get_title();
break;
}
}
I have to write my get_title() function as public…
public static function get_title(){
return 'Title';
}
Otherwise I get the error:
Call to private method Page::get_title()
Which makes me feel as though the function get_info() is essentially redundant. I’d like to be able to make a call from a static method to a private method inside my class for validation purposes. Is this impossible?
PHP > 5.0 btw.
!####### EDIT SOLUTION (BUT NOT ANSWER TO QUESTION) #########!
In case you are curious, my workaround was to instantiate my static function’s class inside the static function.
So, the class name was Page I would do this…
public static function get_info($type){
$page = new Page();
switch($type){
case'title':
$page->get_title();
break;
}
}
public function get_title(){
return 'Title';
}
yes, it’s impossible – a non-static method needs an object to read data from, while the point of a static one is that it has no such object attached. you can think of each non-static method of being passed an implicit argument, the object. you simply don’t have a value to pass this value on to the method if you’re calling from a static function.
update
you can have private static function – I’m not sure if your question might involve a slight misunderstanding of private and static as mutually exclusive concepts