首页 > 编程 > PHP > 正文

php学习--静态变量

2019-11-08 18:49:57
字体:
来源:转载
供稿:网友

class Child{                               public $name;                              public static$nums=0;                function__construct($name){                                              $this->name=$name;                }                publicfunction join_game(){                                              //self::$nums 使用静态变量                       self::$nums+=1;                       echo $this->name."加入堆雪人游戏";                }        }        //创建三个小孩        $child1=new Child("李逵");        $child1->join_game();        $child2=new Child("张飞");        $child2->join_game();        $child3=new Child("唐僧");        $child3->join_game();        //看看有多少人玩游戏        echo "<br/> 有这".Child::$nums;


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表