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';
}
get_info()andget_title()are in the same class? It won’t work ifget_title()resides in a superclass…$thisas there is no object instance, and you can't use$thisto call a static method anyway. But you can useself::to refer to the static class that the method is in, in order to call other methods (private, protected or public) in that static class.get_title()with private access.