Bug #70710 [Nab]: Method compatible declaration issue with parent of class when using trait
| From: | bwoebi@php.net | Date: | Thu, 15 Oct 2015 20:55:51 +0000 |
| Subject: | Bug #70710 [Nab]: Method compatible declaration issue with parent of class when using trait | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-196631@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70710&edit=1
ID: 70710
Updated by: bwoebi@php.net
Reported by: wouter at wouter0100 dot nl
Summary: Method compatible declaration issue with parent of
class when using trait
Status: Not a bug
Type: Bug
Package: Class/Object related
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Addendum: note that use ... as ...; instructions in traits are pure aliases. The method with the
original name still exists in the class.
See also: https://3v4l.org/ANmkM#v700alpha1
(execute() and executeTrait() are defined)
This is necessary, so that calls between methods inside traits don't break, as traits
don't declare their own scope, but are pure compiler-assisted copy&paste.
Previous Comments:
------------------------------------------------------------------------
[2015-10-15 20:50:34] bwoebi@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
PHP is not supporting method overloading.
And it requires declarations to match (Liskov Substitution principle needs to hold: each value I can
pass to a parent class must also be allowed to be passed to a child class),
P.s.: In case of a declaration warning, the method is not added at all.
------------------------------------------------------------------------
[2015-10-14 10:12:10] wouter at wouter0100 dot nl
Description:
------------
When you extend a class and use a trait with the same method, you'll get a declaration error.
Only by overwriting the extended classes method within the class itself, this is fixed.
Test script:
---------------
Method test: https://3v4l.org/gMEGg
Declaration error: https://3v4l.org/IJoio
Current workaround: https://3v4l.org/gIq0E
Expected result:
----------------
That the (strict) warning isn't being shown and I'm able to execute $this->execute for
the parents method and $this->executeTrait for the trait's method.
Actual result:
--------------
See tests.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70710&edit=1