Req->Doc #49515 [Opn]: Class members with the same name ought to raise an E_STRICT error or notice.

From: Date: Mon, 31 Aug 2015 17:06:12 +0000
Subject: Req->Doc #49515 [Opn]: 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-12685@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: Open -Type: Feature/Change Request +Type: Documentation Problem Package: Scripting Engine problem Operating System: Irrelevant PHP Version: 5.3.0 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: $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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.doc.bugs (#12685) next »