#44043 [Opn]: Enforcing a method without specifying the arguments

From: Date: Mon, 04 Feb 2008 20:27:32 +0000
Subject: #44043 [Opn]: Enforcing a method without specifying the arguments
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-121963@lists.php.net to get a copy of this message
ID: 44043 Updated by: helly@php.net Reported By: j dot boggiano at seld dot be Status: Open Bug Type: Class/Object related -Operating System: Windows/Linux +Operating System: * PHP Version: 6CVS-2008-02-04 (snap) New Comment: What we could do is adding '...'. That way you can do stuff like: interface Foo { function bar($first, ...); } Now all classes that derive from Foo must implement the same function protocol, for instance: class Baz { function bar($first, ...) {} } Anything else would violate the inheritance rules. Previous Comments: ------------------------------------------------------------------------ [2008-02-04 18:44:46] j dot boggiano at seld dot be Description: ------------ The purpose of this is to allow an abstract class or an interface to enforce the implementation of a method, without however enforcing the arguments signature. This is -as I understand it- not a bug, but a feature request. Reproduce code: --------------- /*** * This works in PHP5 but does not anymore in PHP6 */ class Parnt { public function foo() {} } class Child extends Parnt { public function foo($arg){} } /*** * Those don't work in either 5 or 6 */ abstract class Abst { abstract public function foo(); } class Child2 extends Abst { public function foo($arg){} } interface Int { public function foo(); } class Child3 implements Int { public function foo($arg){} } Expected result: ---------------- /*** * Proposal for a solution */ abstract class AbstFixed { abstract public function foo; } class Child4 extends AbstFixed { public function foo($arg){} } // => Declaring the method without parenthesis (which currently throws a parse error) would allow the implementations of this method to use any argument signature they please. Actual result: -------------- At the moment those three examples throw a fatal error in PHP6 with : Declaration of Child::foo() must be compatible with that of Parnt::foo() I don't think it is a bug, but I think having the capability to allow variable function signatures would definitely be a plus, especially with PHP6 coming that prevents the first example to work. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44043&edit=1

« previous php.bugs (#121963) next »