Re: Declaration of Bar::__construct() must be compatible with that of Foo::__construct()

From: Date: Wed, 25 Feb 2004 23:34:31 +0000
Subject: Re: Declaration of Bar::__construct() must be compatible with that of Foo::__construct()
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-8132@lists.php.net to get a copy of this message
On Wed, 2004-02-25 at 23:52, Timm Friebe wrote: > On Wed, 2004-02-25 at 23:44, Marcus Boerger wrote: > > Hello Timm, > > > > i had the same expirience today too. And also for me it makes not much > > sense. The constructor shouldn't check inheritance rules. > > Neither should other methods follow this. What if I want to add a > non-default parameter to an overriden method? Some test cases: Should work #1, Bar::connect() adds an argument ------------------------------------------------------------------- <?php interface Connector { function connect($server); } class Foo implements Connector { function connect($server) { } } class Bar extends Foo { function connect($server, $port) { } } ?> Should work #2, Bar::connect() might contain something such as parent::connect('foo.example.com'); ------------------------------------------------------------------- <?php interface Connector { function connect($server); } class Foo implements Connector { function connect($server) { } } class Bar extends Foo { function connect() { } } ?> Should work #3, Bar::connect() might contain something such as parent::connect($dsn->getHost()); ------------------------------------------------------------------- <?php class DSN { } interface Connector { function connect($server); } class Foo implements Connector { function connect($server) { } } class Bar extends Foo { function connect(DSN $dsn) { } } ?> Should work #4, Foo::connect() adds a default argument ------------------------------------------------------------------- <?php interface Connector { function connect($server); } class Foo implements Connector { function connect($server, $port= 42) { } } class Bar extends Foo { function connect($server, $port= 23) { } } ?> Should work #5, both interface and implementer have a default value for the argument "server" ------------------------------------------------------------------- <?php interface Connector { function connect($server= 'localhost'); } class Foo implements Connector { function connect($server= 'localhost') { } } class Bar extends Foo { function connect($server= 'localhost', $port= 23) { } } ?> Should work #6, implementation adds a default value ------------------------------------------------------------------- <?php interface Connector { function connect(); } class Foo implements Connector { function connect($server= 'localhost') { } } class Bar extends Foo { function connect($server= 'localhost', $port= 23) { } } ?> Should NOT work #1, Foo doesn't fully implement connect() ------------------------------------------------------------------- <?php interface Connector { function connect($server); } class Foo implements Connector { function connect() { } } class Bar extends Foo { function connect($server, $port) { } } ?> Should NOT work #2, class / primitive clash on argument ------------------------------------------------------------------- <?php class DSN { } interface Connector { function connect(DSN $dsn); } class Foo implements Connector { function connect($dsn) { } } class Bar extends Foo { function connect($dsn) { } } ?> Should NOT work #3, Foo implements Connector::connect() incorrectly ------------------------------------------------------------------- <?php interface Connector { function connect($server); } class Foo implements Connector { function connect($server, $port) { } } class Bar extends Foo { function connect($server, $port= 23) { } } ?> Should NOT work #4, Foo implements Connector::connect() incorrectly ------------------------------------------------------------------- <?php interface Connector { function connect(); } class Foo implements Connector { function connect($server) { } } class Bar extends Foo { function connect($server, $port) { } } ?> I would simply refrain from calling zend_do_perform_implementation_check() in inheritance. - Timm

Attachment: [text/x-patch] zend_compile.diff
« previous php.internals (#8132) next »