|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-01-19 19:16 UTC] 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 {
}
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
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 { } }