note 119496 deleted from language.oop5.basic by cmb

From: Date: Wed, 22 Jun 2016 10:07:11 +0000
Subject: note 119496 deleted from language.oop5.basic by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-205776@lists.php.net to get a copy of this message
Note Submitter: info at developiu dot it ---- As stated in the documentation, variables and methods live in separated namespaces: $obj->bar refers to the bar attribute and $obj->bar(...) refer to the bar method. This means that if an attribute is invokable, a careful use of parenthesis is necessary to trigger the __invokable magic method, as the following snippet shows: <?php class I { public function __invoke() { echo "invoked\n"; } } class B { public $bar; public function bar() { echo "bar\n"; } } $b=new B; $b->bar=new I; $b->bar(); ($b->bar)(); // output: // bar // invoked ?>

« previous php.notes (#205776) next »