From 727d05975829ab4666b3aa767e49479a5adeea4b Mon Sep 17 00:00:00 2001 From: Christoph Michael Becker Date: Sun, 6 Sep 2015 15:06:02 +0000 Subject: [PATCH] clarified behavior of property access vs. method call (fixes #49515) git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@337758 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/oop5/basic.xml | 69 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/language/oop5/basic.xml b/language/oop5/basic.xml index f5e8930888..a0533f9dda 100644 --- a/language/oop5/basic.xml +++ b/language/oop5/basic.xml @@ -220,6 +220,75 @@ var_dump($obj4 instanceof Child); bool(true) bool(true) bool(true) +]]> + + + + + + Properties and methods + + Class properties and methods live in separate "namespaces", so it is + possible to have a property and a method with the same name. Reffering to + both a property and a method has the same notation, and whether a property + will be accessed or a method will be called, solely depends on the context, + i.e. whether the usage is a variable access or a function call. + + + Property access vs. method call + +bar, PHP_EOL, $obj->bar(), PHP_EOL; +]]> + + &example.outputs; + + + + + + That means that calling an anonymous + function which has been assigned to a property is not directly + possible. Instead the property has to be assigned to a variable first, for + instance. + + + Calling an anonymous function stored in a property + +bar = function() { + return 42; + }; + } +} + +$obj = new Foo(); +$func = $obj->bar; +echo $func(), PHP_EOL; +]]> + + &example.outputs; + +