svn: /phpdoc/en/trunk/language/oop5/ basic.xml
| From: | Christoph Michael Becker | Date: | Sun, 06 Sep 2015 15:06:02 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/oop5/ basic.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-13714@lists.php.net to get a copy of this message | ||
cmb Sun, 06 Sep 2015 15:06:02 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=337758
Log:
clarified behavior of property access vs. method call (fixes #49515)
Bug: https://bugs.php.net/49515 (Assigned) Class members
with the same name ought to raise an E_STRICT error or notice.
Changed paths:
U phpdoc/en/trunk/language/oop5/basic.xml
Modified: phpdoc/en/trunk/language/oop5/basic.xml
===================================================================
--- phpdoc/en/trunk/language/oop5/basic.xml 2015-09-05 23:13:20 UTC (rev 337757)
+++ phpdoc/en/trunk/language/oop5/basic.xml 2015-09-06 15:06:02 UTC (rev 337758)
@@ -224,7 +224,76 @@
</screen>
</example>
</sect2>
+
+ <sect2 xml:id="language.oop5.basic.properties-methods">
+ <title>Properties and methods</title>
+ <para>
+ 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.
+ </para>
+ <example>
+ <title>Property access vs. method call</title>
+ <programlisting role="php">
+<![CDATA[
+class Foo
+{
+ public $bar = 'property';
+
+ public function bar() {
+ return 'method';
+ }
+}
+$obj = new Foo();
+echo $obj->bar, PHP_EOL, $obj->bar(), PHP_EOL;
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+property
+method
+]]>
+ </screen>
+ </example>
+ <para>
+ That means that calling an <link linkend="functions.anonymous">anonymous
+ function</link> which has been assigned to a property is not directly
+ possible. Instead the property has to be assigned to a variable first, for
+ instance.
+ </para>
+ <example>
+ <title>Calling an anonymous function stored in a property</title>
+ <programlisting role="php">
+<![CDATA[
+class Foo
+{
+ public $bar;
+
+ public function __construct() {
+ $this->bar = function() {
+ return 42;
+ };
+ }
+}
+
+$obj = new Foo();
+$func = $obj->bar;
+echo $func(), PHP_EOL;
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+42
+]]>
+ </screen>
+ </example>
+ </sect2>
+
<sect2 xml:id="language.oop5.basic.extends">
<title>extends</title>
<para>