?php
class demo{
public $name;
public static $count=0;
private function __construct($name){
echo "create $name br/>";
$this->name = $name;
self::$count++;
}
public function __destruct(){
echo "destory ".$this->name."br/>";
self::$count--;
}
public static function create($name){
if(self::$count>2){
die("you can only create at most 2 objects.");
}else{
return new self($name);
}
}
}
$one = demo::create("one");
$two = demo::create("two");
$two = null;
$three = demo::create("three");
更多关于PHP相关内容感兴趣的读者可查看本站专题:《php面向对象程序设计入门教程》、《PHP数组(Array)操作技巧大全》、《PHP基本语法入门教程》、《PHP运算与运算符用法总结》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》