PHP static method using private class functions / variables

If I write a public static method in a class, then ...

public static function get_info($type){
        switch($type){
            case'title':
                self::get_title(); 
                break;
        }
    }

I need to write my get_title () function as public ...

public static function get_title(){
        return 'Title';
    }

Otherwise, I get an error:

Call to private method Page::get_title()

Which makes me feel that the function get_info()is essentially redundant. I would like to be able to make the call from the static method a private method inside my class for verification. It's impossible?

PHP> 5.0 btw.

! ####### EDIT THE DECISION (BUT DO NOT ANSWER TO THE QUESTION) #########!

In case you are interested, my workaround was to instantiate a static class of functions inside a static function.

So the class name was a page, I would do it ...

public static function get_info($type){
            $page = new Page();
            switch($type){
                case'title':
                    $page->get_title(); 
                    break;
            }
        }
  public function get_title(){
            return 'Title';
        }
+5
2

, - , - , . , . , , .

- , .

+2

, , . get_title() - - ? get_info() get_title(), ( ), get_title() , - . get_info() get_title() - . get_title() , .

(, ) ( ), .

EDIT: ...

// Enable full error reporting to make sure all is OK
error_reporting(E_ALL | E_STRICT);

class MyStaticClass {

 public static function get_info($type){
  switch($type){
   case 'title':
    return self::get_title(); 
    break;
   }
 }


 private static function get_title() {
  return 'Title';
 }
}

// OK - get_info() calls the private method get_title() inside the static class
echo MyStaticClass::get_info('title');

// ERROR - get_title() is private so cannot be called from outside the class
echo MyStaticClass::get_title();
+9

All Articles