目前共有1篇帖子。
PHP类方法中的静态变量原来是在所有类之间共享的!
1樓 巨大八爪鱼 2015-11-25 11:42
<?php
class Apple {
    public function show() {
        static $number = 10;
        echo "$number<br>";
        $number++;
    }
}
$app1 = new Apple();
$app1->show();
$app2 = new Apple();
$app2->show();
$app2->show();
?>
输出:
10
11
12

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
 
 
©2010-2025 Arslanbar [手機版] [桌面版]
除非另有聲明,本站採用共享創意姓名標示-相同方式分享 3.0 Unported許可協議進行許可。