|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-09-28 11:33 UTC] maciej dot sz at gmail dot com
Description: ------------ This happens when method of a sub-class introduce new, optional parameters which are needed for an interface implementation. If a trait is source for the implementation of that method then a fatal error is triggered: Fatal error: Declaration of Base::push() must be compatible with I::push Bug #60153 might be related as it considers opposite situation. I've checked this with: 5.4.1 5.4.7 5.5-dev (snap 201209280930) Test script: --------------- <?php error_reporting(E_ALL); interface I { public function push($val, $scope = null); } trait T { public function push($val, $scope = null){} } class Base { public function push($val){} } class Sub extends Base { use T; } $SubReflection = new ReflectionClass('Sub'); // this shows correct push() method, compatible with 'I' interface: echo $SubReflection->getMethod('push'); // however adding 'implements I' triggers fatal error: class SubImplements extends Base implements I { use T; } Expected result: ---------------- No errors (interface is implemented properly) Actual result: -------------- Fatal error: Declaration of Base::push() must be compatible with I::push($val, $scope = NULL) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 06:00:02 2025 UTC |
In case if someone has the same problem I came up with an ugly workaround, which requires yet another sub class: <?php class Sub extends Base { use T; } class SubSub extends Sub implements I {}