1 class Person 2 { 3 const HOST = 'localhost'; 4 5 public function say(){ 6 echo 'hello'; 7 } 8 } 9 10 echo Person::HOST;
1 final class Person
2 { 3 const HOST = 'localhost'; 4 5 public function say(){ 6 echo 'hello'; 7 } 8 }
1 class Person 2 { 3 const HOST = 'localhost'; 4 5 final public function say(){ 6 echo 'hello'; 7 } 8 }
-
1 class Person 2 { 3 public $name; 4 static public $num; 5 6 public function __construct($n){ 7 $this->name = $n; 8 Person::$num++; 9 } 10 } 11 new Person('user1'); 12 new Person('user2'); 13 new Person('user3'); 14 15 echo Person::$num; # 3
1 # 2 3 class Person 4 { 5 public $name; 6 7 public function __construct($n){ 8 $this->name = $n; 9 } 10 11 public function say(){ 12 echo "
my name is {$this->name}
"; 13 } 14 15 static public function sum($i,$j){ 16 return $i+$j; 17 } 18 } 19 20 echo Person::sum(5,25);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)