The content of this article is about the points to note about PHP attributes and methods. It has certain reference value. Now I share it with you. Friends in need can refer to it
/*
1. Regarding the attribute value, you can declare the attribute and assign a value, or you can declare the attribute without assigning a value first
If you do not assign a value, the initial value of the attribute is null
2. For classes in PHP, the attribute must be a "direct Value"
is any "value" of the 8 types
cannot be: the value of expression 1 2
cannot be: the return value of the function time();
* /
class Human { public $age = 0; }$a = new Human();echo $a->age,'<br >';
class People { public $age; }$b = new People(); var_dump($b->age);echo '<br >';
//类中可以重名class clock { public function time() { echo '现在的时间戳是aaaa'; } public function t() { return '内部的t'; } public function time2() { echo '现在的真正时间戳是',time(),'<br >'; // 注意:此处调用的是系统的time()函数 echo $this->t(); // 注意:此处调用的是自身的t函数 } }$c = new clock();$c->time();echo '<br >';$c->time2();
The above is the detailed content of Things to note about PHP properties and methods. For more information, please follow other related articles on the PHP Chinese website!