Home > Backend Development > PHP Tutorial > Things to note about PHP properties and methods

Things to note about PHP properties and methods

不言
Release: 2023-03-24 20:24:02
Original
1394 people have browsed it

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,&#39;<br >&#39;;
Copy after login
class People {
    public $age;
}$b = new People();
var_dump($b->age);echo &#39;<br >&#39;;
Copy after login
//类中可以重名class clock {
    public function time() {
        echo &#39;现在的时间戳是aaaa&#39;;
    }    public function t() {
        return &#39;内部的t&#39;;
    }    public function time2() {
        echo &#39;现在的真正时间戳是&#39;,time(),&#39;<br >&#39;;        // 注意:此处调用的是系统的time()函数
        echo $this->t(); 
        // 注意:此处调用的是自身的t函数
    }
}$c = new clock();$c->time();echo &#39;<br >&#39;;$c->time2();
Copy after login

           


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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template