Edit report at https://bugs.php.net/bug.php?id=64235&edit=1
ID: 64235
Comment by: gron@php.net
Reported by: imenem at inox dot ru
Summary: Insteadof not work for class method in 5.4.11
Status: Feedback
Type: Bug
Package: Scripting Engine problem
Operating System: Debian GNU/Linux
PHP Version: 5.4.11
Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
Hi:
The insteadof and as operators where not intended to be used with classes.
The syntax is intended to convey that the use operation is refined by specifying how to
resolve conflicts __between__ traits.
That's the idea at least.
My solution for the initial problem presented would be to provide a method such as follows in
the TestChildClass:
public function method() {
parent::method();
}
I understand that this is not ideal, and requires you to repeat yourself.
However, it is consistent in the sense that traits are traits and not classes, and both get
mixed up as little as possible,
However, beside the academic notion of purity, I can see that `TestParentClass::method
insteadof TestTrait;` is useful.
[I wonder whether parent::method insteadof TestTrait; should be supported as well.]
Laruence's example with TestParentClass::method as methodParent; is however
problematic.
Traits are not supposed to conflict with classes, but with traits. So, allowing the
introduction of aliases for method of the super class seems to me as something that is
problematic, because it mixes up the concepts.
If you need an alias for the method of a parent class, the classic way would be:
public function foo() {
parent::bar();
}
No?
Well, that's my point of view.
So, from a practical point of view, referring to the parent (and only the direct parent) class
in insteadof might be a useful/acceptable feature.
The use in conjunction with as seems to be something I would advocate against.
In either way, beside bugs that made this possible in the first place, I would consider both
ideas as new features that need to be documented/discussed.
I thought that we had a test that only the traits listed in the use clause can be used
for
the as/insteadof operators, but that's either broken or not there, or
a bug that was fixed
in 5.4.11 as the original report suggests.
Therefore, from my perspective, 5.4.11 shows the behavior that's intended by the spec/RFC.
Best regards
Stefan
Previous Comments:
------------------------------------------------------------------------
[2013-02-20 08:22:01] laruence@php.net
reeze, *before* doesn't always means *RIGHT*.
------------------------------------------------------------------------
[2013-02-20 08:16:52] reeze@php.net
@laurence the code you paste above works the same as before:
http://3v4l.org/UpMCW#v5411 that didn't break
After read some doc I assume class is not suitable in context of 'insteadof',
so let's wait for Stefan or more discussion :)
------------------------------------------------------------------------
[2013-02-20 08:12:40] laruence@php.net
form the context, insteadof works at class make sense.
reeze, whatever the RFC is, your fix simply skip check for classes at all, which
will make the test script I paste result in "FATAL ERROR, undefined method", that
is not acceptable.
------------------------------------------------------------------------
[2013-02-20 08:07:58] laruence@php.net
The following patch has been added/updated:
Patch Name: bug64235.patch
Revision: 1361347678
URL: https://bugs.php.net/patch-display.php?bug=64235&patch=bug64235.patch&revision=1361347678
------------------------------------------------------------------------
[2013-02-20 08:04:11] dmitry@php.net
It's hard to say what is expected :)
I thought only traits may be used in context of "insteadof", now I'm not sure.
I sent the question to Stefan Marr. Lets wait for his opinion.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=64235
--
Edit this bug report at https://bugs.php.net/bug.php?id=64235&edit=1