View Single Post
Old 02-02-2009, 01:14 PM   #1 (permalink)
planepixel
The Contributor
 
planepixel's Avatar
 
Join Date: Feb 2009
Posts: 28
Thanks: 10
planepixel is on a distinguished road
Default help with object code

hi I was reading php manual on object and classes and came across this code. i have no idea what this code is doing. i tried to figure it out but could not get anything from it.


PHP Code:
<?php
class db {
  
//...
  
private static $instance;
  
//...
  
public static function singleton() {
    if(!isset(
self::$instance)) {
      
// what is the purpose of following two lines
      
$c __CLASS__;
      
self::$instance = new $c();
      
// End of lines
    
}
    return 
self::$instance;
  }
  
//...
}
?>
the bold text is the main issue. could anybody please explain what this chunk of code is doing.
Thanks
planepixel is offline  
Reply With Quote