Using Static Methods And Properties To Limit Instances Of A Class (Php 5 Only)

<?phpclass Shop {
  private static $instance;
  public $name="shop";  private function ___construct() {
  }  public static function getInstance() {
    if ( empty( self::$instance ) ) {
    self::$instance = new Shop();
    }
    return self::$instance;
  }
}$first = Shop::getInstance();
$first-> name="A";$second = Shop::getInstance();
print $second -> name;
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.