构造函数和析构函数是什么? http://www.phpe.net/articles/398.shtml看这个 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1.构造函数并在建立一个对象实例时被执行2.析构函数,相反于构造函数. PHP调用它们来将一个对象从内存中销毁给你一个例子<?phpclass Counter { private static $count = 0; function __construct() { self::$count++; } function __destruct() { self::$count--; } function getCount() { return self::$count; } } //建立第一个实例 $c = new Counter(); //输出1 print($c->getCount() . "n"); //建立第二个实例 $c2 = new Counter(); //输出2 print($c->getCount() . "n"); //销毁实例 $c2 = NULL; //输出1 print($c->getCount() . "n"); ?> 一个关于打印目录的问题 安装php5.2.5和mysql5.045后phpmyadmin报错 关于adodb 判断字符串是否为6位的颜色代码,怎么写? 构造函数访问权限问题 base64_encode加密问题 求一个判断数字的正则(高手进) 为什么这样的二维数组foreach后只有最后一个值输入? 高手求救! 有关asp.Jsp.php三者之间的关系!高手请进啊! 这一语句哪有问题?着急啊 PHP是不是在RED HART服务器下。我的网页全是 gb2132简体中文的.能正常用吗。
<?php
class Counter
{
private static $count = 0; function __construct()
{
self::$count++;
} function __destruct()
{
self::$count--;
} function getCount()
{
return self::$count;
}
} //建立第一个实例
$c = new Counter(); //输出1
print($c->getCount() . "
n"); //建立第二个实例
$c2 = new Counter(); //输出2
print($c->getCount() . "
n"); //销毁实例
$c2 = NULL; //输出1
print($c->getCount() . "
n");
?>