Bug #71414 [Opn->Csd]: Fatal error when using interface trait and inheritance
| From: | krakjoe@php.net | Date: | Sat, 26 Mar 2016 23:55:41 +0000 |
| Subject: | Bug #71414 [Opn->Csd]: Fatal error when using interface trait and inheritance | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200137@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71414&edit=1
ID: 71414
Updated by: krakjoe@php.net
Reported by: krzysiekpiasecki at gmail dot com
Summary: Fatal error when using interface trait and
inheritance
-Status: Open
+Status: Closed
Type: Bug
Package: Class/Object related
Operating System: OS X 10.9.5
PHP Version: 7.0.2
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of krakjoe
Revision: http://git.php.net/?p=php-src.git;a=commit;h=4327370d1308eab3c611fc6994e67048a18f92ef
Log: fix #71414 (Interface method override inherited method and implemented in a trait causes fatal
error)
Previous Comments:
------------------------------------------------------------------------
[2016-01-19 22:41:53] requinix@php.net
Oh, I see what you mean. The trait's method should overwrite the inherited method, and since
stuff like https://3v4l.org/dCZ9h works without the trait,
using the trait should also be allowed.
------------------------------------------------------------------------
[2016-01-19 22:24:26] krzysiekpiasecki at gmail dot com
I wrote, that method Y in TraitY is well defined and it is according to InterfaceY
No fatal error when method public y():string is defined in the class body not only in a trait.
What's the difference?
class Y extends X implements InterfaceY {
use TraitY;
public function y(): string {
}
}
------------------------------------------------------------------------
[2016-01-19 21:18:19] requinix@php.net
It is not "well defined": X's y() must also have the string return type declaration
to be compatible.
https://wiki.php.net/rfc/return_types
https://3v4l.org/lG7t4
------------------------------------------------------------------------
[2016-01-19 19:16:31] krzysiekpiasecki at gmail dot com
Description:
------------
Interface method override inherited method and implemented in a trait causes fatal error
Test script:
---------------
interface InterfaceY {
public function y(): string;
}
trait TraitY {
public function y(): string {
}
}
class X {
public function y() {
}
}
class Y extends X implements InterfaceY {
use TraitY;
}
Expected result:
----------------
No fatal error. Method Y in TraitY is well defined
Actual result:
--------------
Fatal error: Declaration of X::y() must be compatible with Y::y(): string
PS
__No fatal error__ when:
class Y extends X implements InterfaceY {
use TraitY;
public function y(): string {
}
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71414&edit=1