What does private static do in php?

Associate
Joined
4 Mar 2007
Posts
315
Location
United Kingdom
Ok so I set myself up a class such as:

PHP:
class myClass{

 private static $_inst;

 private function __construct(){
  // Execute my constructors here?
   $this->_something();
 }

 private static function getInstance(){
   if(!self::$_inst){
     self::$_inst = new myClass();
   }
   return self::$_inst;
 }

 private function _something(){
   $xyz = "goodbye";
 }

 public function somethingElse(){
   $abc = "hello";
 }

}

I understand that looking at the __construct is the first thing that gets executed correct? So I would go about setting up my constructors here, then calling it in the main file to create an instance.

However why would I need to use private static, and not just private if private is just keeping the data to the particular class? What differs with statics?

In the main file for instance, I could do:

PHP:
require_once('class.myClass.php');
$instance = myClass::getInstance();
$instance->somethingElse();

As somethingElse is a public function so aside yet if I were to do the same with something() it wouldn't work as it is private and relative to the class. So why make a private static?
 
Back
Top Bottom