Home > Backend Development > PHP Tutorial > Detailed explanation of PHP properties and method examples

Detailed explanation of PHP properties and method examples

小云云
Release: 2023-03-22 21:18:02
Original
1436 people have browsed it

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,&#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

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!

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