Home > Backend Development > PHP Tutorial > PHP 类属性问题

PHP 类属性问题

WBOY
Release: 2016-06-06 20:06:53
Original
823 people have browsed it

为什么类内部使用属性不需要用$符号

class classname {

<code>        $attribute;
        function get() {
                echo $this->attribute; 
                //  为什么不是$this->$attribute; 
        }</code>
Copy after login
Copy after login

}

回复内容:

为什么类内部使用属性不需要用$符号

class classname {

<code>        $attribute;
        function get() {
                echo $this->attribute; 
                //  为什么不是$this->$attribute; 
        }</code>
Copy after login
Copy after login

}

http://php.net/manual/zh/language.oop5.properties.php

多看文档吧,加$又是个变量,

假设你赋值了$attribute = 'age',$this->$attribute相当于调用$this->age

而你没有为attribute赋值时那你调用了什么?

Related labels:
php
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