php中使用static方法

 1 <?php
 2 
 3 class Char{
 4     public static $number = 0;
 5     public static $name;
 6     
 7     function __construct($what){
 8         self::$name = $what;
 9     }
10     public static function  Join(){
11         self::$number++;
12         echo self::$number," Is :",self::$name,"<br />";
13     }
14     
15 }
16 
17 $test = new Char('a');
18 Char::Join();
19 #注意, 在静态方法中不能访问非静态变量

#Char::Join();
#$test->Join();
#$test::Join();
可以这样调用


posted on 2017-02-24 08:42  Perl6  阅读(1006)  评论(0编辑  收藏  举报

导航