Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

member variable and member function have the same name

Tags:

php

class test {
    public $isNew;
    public function isNew(){}
}

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

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

like image 829
user198729 Avatar asked Mar 03 '10 13:03

user198729


2 Answers

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.

like image 189
Gumbo Avatar answered Oct 09 '22 01:10

Gumbo


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

like image 44
dnagirl Avatar answered Oct 09 '22 01:10

dnagirl