From: a dot dotreppe at aspyct dot org Operating system: Windows Vista 32bit PHP version: 5.3.0 PHP Bug Type: Feature/Change Request Bug description: Default arguments on interface implicitly passed to implementing classes
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 -- Edit bug report at http://bugs.php.net/?id=49261&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49261&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49261&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49261&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49261&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49261&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49261&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49261&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49261&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49261&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49261&r=support Expected behavior: http://bugs.php.net/fix.php?id=49261&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49261&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49261&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49261&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49261&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49261&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49261&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49261&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49261&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49261&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49261&r=mysqlcfg