目前共有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许可协议进行许可。