|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-01-01 16:03 UTC] jani@php.net
-Package: Feature/Change Request
+Package: Class/Object related
-Operating System: Windows Vista 32bit
+Operating System: *
[2020-10-04 03:42 UTC] corey dot taylor dot fl at gmail dot com
[2020-10-04 04:07 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2020-10-04 04:07 UTC] requinix@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
Description: ------------ Hi, The aim of interfaces is to provide the same external behavior, no matter what class implements it. Maybe it would be nice for interfaces to be able to force a default value for argument on implemented methods. Moreover, that way we could change all method's default argument by modifying it on one place only: the interface. Reproduce code: --------------- interface Fetchable { const FETCH_ASSOC = 1; function fetch($fetchStyle=self::FETCH_ASSOC); function fetchAll($fetchStyle=self::FETCH_ASSOC); } class PDOLayerStatement implements Fetchable { /* This one works fine, but I have to know the default value on interface, * and even reference the interface, * which will raise the amount of maintenance work */ public function fetch($fetchStyle=Fetchable::FETCH_ASSOC); /* These two won't work, sadly :( */ public function fetch($fetchStyle) {} public function fetchAll($fetchStyle) {} } Expected result: ---------------- It would be nice if PHP could automatically give Fetchable::FETCH_ASSOC as default value for $fetchStyle in every implementing class. Actual result: -------------- Fatal error: Declaration of PDOLayerStatement::fetch() must be compatible with that of Fetchable::fetch() in C:\xampp\htdocs\aspyct\src\test.php