This article mainly shares with you detailed explanations of PHP attributes and method examples, mainly in the form of text and code. I hope it can help everyone.
/*
1. Regarding attribute values, you can declare the attribute and assign a value, or you can declare the attribute without assigning a value first.
If no value is assigned, the initial value of the attribute is null
2 , the class in PHP, the attribute must be a "direct value"
is any "value" of 8 types
cannot be: the value of expression 1+2
cannot be: function The return value of 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();
Related recommendations:
##Commonly used global properties and methods in JavaScript
JavaScript common global properties and methods record accumulation_Basic knowledge
Summary of event object properties and methods in jquery_jquery
The above is the detailed content of Detailed explanation of PHP properties and method examples. For more information, please follow other related articles on the PHP Chinese website!