Bug #71414 [Com]: Fatal error when using interface trait and inheritance

From: Date: Tue, 19 Jan 2016 22:24:26 +0000
Subject: Bug #71414 [Com]: Fatal error when using interface trait and inheritance
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198778@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 Comment by: krzysiekpiasecki at gmail dot com Reported by: krzysiekpiasecki at gmail dot com Summary: Fatal error when using interface trait and inheritance Status: Not a bug 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: 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 { } } Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#198778) next »