<?php
class CarSingleton {
var $instance = NULL;
function CarSingleton($fromGetInstance = false){
if(M_E != $fromGetInstance){
trigger_error('do not instantiate
directly');
}
}
function &washCar(){
if(!$this->instance){
$this->instance = new CarSingleton(M_E);
return $this->instance;
}
}
}
// try to test
$obj = CarSingleton::washCar();
$obj2 = new CarSingleton;
?>
| Series this article: OOP Pattern - Singleton: Enter Point OOP Pattern - Singleton: Using One Instance Tag: oop, pattern, singleton Category: PHP Classes Post : February 19th 2008 Read: 1,192 blog comments powered by Disqus |