note 119496 added to language.oop5.basic

From: Date: Tue, 21 Jun 2016 16:02:08 +0000
Subject: note 119496 added to language.oop5.basic
Groups: php.notes 
Request: Send a blank email to php-notes+get-205772@lists.php.net to get a copy of this message
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 ?> ---- Server IP: 72.52.91.14 Probable Submitter: 151.49.209.70 ---- Manual Page -- http://php.net/manual/en/language.oop5.basic.php Edit -- https://master.php.net/note/edit/119496 Del: integrated -- https://master.php.net/note/delete/119496/integrated Del: useless -- https://master.php.net/note/delete/119496/useless Del: bad code -- https://master.php.net/note/delete/119496/bad+code Del: spam -- https://master.php.net/note/delete/119496/spam Del: non-english -- https://master.php.net/note/delete/119496/non-english Del: in docs -- https://master.php.net/note/delete/119496/in+docs Del: other reasons-- https://master.php.net/note/delete/119496 Reject -- https://master.php.net/note/reject/119496 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#205772) next »