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; + +