Detailed explanation of PHP object-oriented this binding

小云云
Release: 2023-03-22 20:56:01
Original
1553 people have browsed it

This article mainly shares with you the detailed explanation of PHP object-oriented this binding. It mainly explains it to you in the form of code. I hope it can help you.

About this binding

class Human {
    public $name = 'lisi';    public function who() {
        echo $this->name;
    }    /*
    public function test() {
        echo $name;
    }
    *//*
和java、c++相比
方法体内想访问调用者的属性,必须用$this
如果不加,则理解为方法内部的一个局部变量.
*/}$a = new Human();echo $a->name,&#39;<br >&#39;; //lisi$a->who(); //lisi//$a->test();
Copy after login
Copy after login

About this binding

class Human {
    public $name = &#39;lisi&#39;;    public function who() {
        echo $this->name;
    }    /*
    public function test() {
        echo $name;
    }
    *//*
和java、c++相比
方法体内想访问调用者的属性,必须用$this
如果不加,则理解为方法内部的一个局部变量.
*/}$a = new Human();echo $a->name,&#39;<br >&#39;; //lisi$a->who(); //lisi//$a->test();
Copy after login
Copy after login

Related recommendations:

Detailed explanation of this binding in JavaScript

The above is the detailed content of Detailed explanation of PHP object-oriented this binding. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!