成员变量和成员函数具有相同的名称

时间:2020-12-09 16:47:22
class test {
    public $isNew;
    public function isNew(){}
}

$ins = new test();
$ins->isNew

Here,how does php parse $ins->isNew?

在这里,php如何解析$ ins-> isNew?

3 个解决方案

#1


25  

PHP is not a functional programming language where functions are also data. So $ins->isNew wouldn’t be ambiguous to either refer to the method isNew or the attribute isNew. $ins->isNew is always an attribute and $ins->isNew() a method call.

PHP不是函数编程语言,其中函数也是数据。所以$ ins-> isNew对于引用方法isNew或属性isNew不会有歧义。 $ ins-> isNew始终是一个属性,而$ ins-> isNew()是一个方法调用。

#2


5  

$ins->isNew is the variable. $ins->isNew() is the function.

$ ins-> isNew是变量。 $ ins-> isNew()是函数。

#3


4  

See the chapter on Class Basic in the PHP manual:

请参阅PHP手册中有关Class Basic的章节:

$ins->isNew   // class member
$ins->isNew() // class method

#1


25  

PHP is not a functional programming language where functions are also data. So $ins->isNew wouldn’t be ambiguous to either refer to the method isNew or the attribute isNew. $ins->isNew is always an attribute and $ins->isNew() a method call.

PHP不是函数编程语言,其中函数也是数据。所以$ ins-> isNew对于引用方法isNew或属性isNew不会有歧义。 $ ins-> isNew始终是一个属性,而$ ins-> isNew()是一个方法调用。

#2


5  

$ins->isNew is the variable. $ins->isNew() is the function.

$ ins-> isNew是变量。 $ ins-> isNew()是函数。

#3


4  

See the chapter on Class Basic in the PHP manual:

请参阅PHP手册中有关Class Basic的章节:

$ins->isNew   // class member
$ins->isNew() // class method