Doc #49515 [Asn->Csd]: Class members with the same name ought to raise an E_STRICT error or notice.
| From: | cmb@php.net | Date: | Sun, 06 Sep 2015 15:06:41 +0000 |
| Subject: | Doc #49515 [Asn->Csd]: Class members with the same name ought to raise an E_STRICT error or notice. | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12724@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=49515&edit=1
ID: 49515
Updated by: cmb@php.net
Reported by: oorza2k5 at gmail dot com
Summary: Class members with the same name ought to raise an
E_STRICT error or notice.
-Status: Assigned
+Status: Closed
Type: Documentation Problem
Package: Scripting Engine problem
Operating System: Irrelevant
PHP Version: 5.3.0
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation better.
Previous Comments:
------------------------------------------------------------------------
[2015-09-06 15:06:04] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=337758
Log: clarified behavior of property access vs. method call (fixes #49515)
------------------------------------------------------------------------
[2015-08-31 17:06:11] cmb@php.net
$obj->foo() will never call a closure stored in property $foo, but
instead will always look only for method foo, see
<https://3v4l.org/WVWGM>. So there's no need to care
for name
clashes between properties and methods.
It seems the docs can be improved with regard to this behavior.
------------------------------------------------------------------------
[2009-12-03 04:58:06] oorza2k5 at gmail dot com
Any chance this gets looked at?
------------------------------------------------------------------------
[2009-09-09 20:56:41] oorza2k5 at gmail dot com
Description:
------------
When you store a closure as a class property, while having a method with the same name, it's
unclear (I don't think this is documented anywhere) what $obj->name($arg) will do. If this
is the case, a warning about code ambiguity ought to be raised.
This is a potentially very confusing scenario, perhaps an E_STRICT error ought to be raised whenever
two class members share the same name, regardless of whether a property contains a closure or not.
Reproduce code:
---------------
class foo {
public $bar;
public function bar() {
echo "Inside a method!";
}
}
$obj = new foo();
$obj->bar = function() { echo "Inside a closure!"; };
$obj->bar();
Expected result:
----------------
Notice: ....
Inside a method!
Actual result:
--------------
Inside a method!
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=49515&edit=1