{"id":146,"title":"\u9759\u6001\u6210\u5458","good":0,"bad":0,"hit":2458,"created_at":"2015-01-12 14:56:35","content":"
\u9759\u6001\u6210\u5458\u5305\u62ec\u9759\u6001\u5c5e\u6027\u548c\u9759 \u6001\u65b9\u6cd5\uff0c\u7528static\u5b9a\u4e49,\u7528::\u65b9\u5f0f\u8bbf\u95ee<\/p>
\u76f8\u5f53\u4e8e\u662f\u67d0\u4e00\u4e2a\u7c7b\u7684\u516c\u5171\u5c5e\u6027\uff0c\u4e0d\u7ba1\u5bf9\u8c61\u662f\u5426\u5b9e\u4f8b\u5316\u65f6\uff0c\u4ed6\u90fd\u5b58\u5728\u5e76\u4e14\u53ef\u4ee5\u4f7f\u7528\uff1b\u5f53\u5b9e\u4f8b\u5316\u7684\u5bf9\u8c61\u88ab\u9500\u6bc1\u65f6\uff0c\u9759\u6001\u5c5e\u6027\u548c\u65b9\u6cd5\u4e0d\u4f1a\u968f\u7740\u5bf9\u8c61\u9762\u9500\u6bc1\uff1b<\/p>
\u4f8b\u5b50\uff1a\u5f53\u5b9e\u4f8b\u5316\u53ca\u9500\u6bc1\u5bf9\u8c61\u65f6\uff0c\u8bb0\u5f55\u5bf9\u8c61\u7684\u4e2a\u6570<\/p>
<?php
class Student{
public static $count=0;
public function __construct(){
Student::$count++;\/\/\u4e5f\u53ef\u5199\u6210self::$count++
}
public function __destruct(){
Student::$count--;\/\/\u4e5f\u53ef\u5199\u6210self::$count--
}
}
$o1=new Student();
$o2=new Student();
$o3=new Student();
unset($o2);
echo Student::$count;
?><\/p>
\u8fd0\u884c\u7ed3\u679c\uff1a2<\/p>
<\/p>
<\/p>
\u4f8b\u5b50\uff1a\u9759\u6001\u65b9\u6cd5<\/p>
<?php
class Student{
\/\/\u9759\u6001\u5c5e\u6027
public static $count=0;
public function __construct(){
Student::$count++;\/\/\u4e5f\u53ef\u5199\u6210self::$count++
}
public function __destruct(){
Student::$count--;\/\/\u4e5f\u53ef\u5199\u6210self::$count--
}
\/\/\u9759\u6001\u65b9\u6cd5
public static function f1(){
echo 'static function f1';
}
}
Student::f1();
?><\/p>
\u8fd0\u884c\u7ed3\u679c\uff1astatic function f1<\/p>
<\/p>
\u4f8b\u5b50\uff1a\u9759\u6001\u65b9\u6cd5\u4e0e\u975e\u9759\u6001\u65b9\u6cd5\u7684\u533a\u522b\u5728\u4e8e$this\u7684\u4f7f\u7528\u4e0a\uff0c\u53ea\u6709\u4f7f\u7528\u5bf9\u8c61\u8c03\u7528\u975e\u9759 \u6001\u65b9\u6cd5\u65f6\u624d\u53ef\u4ee5\u4f7f\u7528$this,\u9759\u6001\u65b9\u6cd5\u65e0\u8bba\u5982\u4f55\u4e5f\u4e0d\u80fd\u5bf9$this\u505a\u5904\u7406\uff1b<\/strong> <?php
<\/p>
class Student{
\/\/\u9759\u6001\u65b9\u6cd5
public static function f1(){
var_dump($this);
}
\/\/\u975e\u9759\u6001\u65b9\u6cd5
public function f2(){
var_dump($this);
}
}
$o=new Student();
$o->f1();\/\/null
$o->f2();\/\/object
Student::f1();\/\/null
Student::f2();\/\/null
?><\/p>"}