Bug #76370 [Com]: Fatal error instead of warning when extending class that implements interface

From: Date: Sun, 05 Aug 2018 07:58:31 +0000
Subject: Bug #76370 [Com]: Fatal error instead of warning when extending class that implements interface
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216604@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76370&edit=1 ID: 76370 Comment by: Wes dot example at example dot org Reported by: kinglozzer at gmail dot com Summary: Fatal error instead of warning when extending class that implements interface Status: Open Type: Bug Package: Class/Object related Operating System: Mac OS X PHP Version: 7.2.5 Block user comment: N Private report: N New Comment: Not only it shouldn't be a fatal error, but shouldn't be a warning either. Parameters are optional and untyped in all the signatures, hence going to one to the other should never cause errors. That is because php does not reject trailing parameters. function bar(mixed $one = null, mixed ...$foo){} function bar(mixed $one = null, mixed $two = null){} function bar(mixed ...$foo){} function bar(){} these are all compatible... because no parameter is ever required, in all of them Previous Comments: ------------------------------------------------------------------------ [2018-05-24 08:37:31] kinglozzer at gmail dot com Description: ------------ If a class implements an interface, any child classes method definitions must match the *parent class* exactly (not the interface) or a fatal error will occur. Unexpected behaviour - fatal error: https://3v4l.org/BeFp5 Expected behaviour - warning: https://3v4l.org/ZhHrE (without implementing an interface). The introduction of an interface to the base class should not affect the behaviour of child classes. Test script: --------------- https://3v4l.org/BeFp5 Expected result: ---------------- Warning: Declaration of Bar::method() should be compatible with Foo::method($arg = NULL) Actual result: -------------- Fatal error: Declaration of Bar::method() must be compatible with Foo::method($arg = NULL) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76370&edit=1

« previous php.bugs (#216604) next »