Settings | Sign in | Sign up

There is currently 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.