php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #49515 Class members with the same name ought to raise an E_STRICT error or notice.
Submitted: 2009-09-09 20:56 UTC Modified: 2015-09-06 15:06 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: oorza2k5 at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.0 OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: oorza2k5 at gmail dot com
New email:
PHP Version: OS:

 

 [2009-09-09 20:56 UTC] 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!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-03 04:58 UTC] oorza2k5 at gmail dot com
Any chance this gets looked at?
 [2010-12-20 13:20 UTC] jani@php.net
-Package: Feature/Change Request +Package: Scripting Engine problem
 [2015-08-31 17:06 UTC] cmb@php.net
-Type: Feature/Change Request +Type: Documentation Problem -Assigned To: +Assigned To: cmb
 [2015-08-31 17:06 UTC] 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.
 [2015-09-06 15:06 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=337758
Log: clarified behavior of property access vs. method call (fixes #49515)
 [2015-09-06 15:06 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2015-09-06 15:06 UTC] cmb@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 14:01:30 2024 UTC