Settings | Sign in | Sign up

The author has 1 post.

PHP类方法中的静态变量原来是在所有类之间共享的!

Floor 1 巨大八爪鱼 11/25/15 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

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.