Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56803 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2126 invoked from network); 6 Dec 2011 14:01:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Dec 2011 14:01:31 -0000 Authentication-Results: pb1.pair.com header.from=ekneuss@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ekneuss@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.170 as permitted sender) X-PHP-List-Original-Sender: ekneuss@gmail.com X-Host-Fingerprint: 209.85.215.170 mail-ey0-f170.google.com Received: from [209.85.215.170] ([209.85.215.170:50879] helo=mail-ey0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5B/F0-30975-A302EDE4 for ; Tue, 06 Dec 2011 09:01:30 -0500 Received: by eaao13 with SMTP id o13so752731eaa.29 for ; Tue, 06 Dec 2011 06:01:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=bZ8Ed4lYZNg5kT5mDWJzIcOWY2Ez4BvJH0m4HKNCIjM=; b=P00ZcsuXEiDsPHiY7v+yKSDElO6kVuP/3CgqeyeEvgth+1Lxsi9GjQckQu7ZxKpAOR kDoyTgzrAcPN1t75AYbNmHBqQbfENOSc4uGum7g3q2IRz2Ta/tk/ZIn+NUZKPcl5gpA/ B99hJ2idGVWQRar4CeELtLqIVmSjr469Qfrbo= MIME-Version: 1.0 Received: by 10.213.104.140 with SMTP id p12mr2407510ebo.46.1323180085602; Tue, 06 Dec 2011 06:01:25 -0800 (PST) Sender: ekneuss@gmail.com Received: by 10.204.192.72 with HTTP; Tue, 6 Dec 2011 06:01:25 -0800 (PST) In-Reply-To: References: Date: Tue, 6 Dec 2011 15:01:25 +0100 X-Google-Sender-Auth: 6lmMHIF_X02OS9gTlsBpezBrKH8 Message-ID: To: jpauli Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=000e0cd1e24cf9ec5504b36cde2d Subject: Re: [PHP-DEV] One more Liskov Subs. and parameter checking notice From: colder@php.net (Etienne Kneuss) --000e0cd1e24cf9ec5504b36cde2d Content-Type: text/plain; charset=UTF-8 Hi, On Tue, Dec 6, 2011 at 14:54, jpauli wrote: > Greetings PHP Intern@ls :) > > There is a PHP behavior I disagree with regarding OO model. > It's been here for a long time (5.0 ??, at least 5.2, 5.3 and 5.4) , here > it is : > > interface Iface1 { } > interface Iface2 extends Iface1 { } > > class Foo { > public function bar(Iface1 $arg) { } > } > > class Foo2 extends Foo { > public function bar(Iface2 $arg) { } > } > ?> > Strict Standards: Declaration of Foo2::bar() should be compatible with that > of Foo::bar() > > > I find this wrong. > Liskov (and the error message) says we must stay "compatible" in our > inheritence. > The fact is that we are in the code above : > - A uses IfaceA > - B extends A > - B should be able to overwrite A's method typing their IfaceA params on > IfaceB, if IfaceB extends IfaceA (and is thus compatible with it). > Thoughts ? > No, that makes B incompatible with A. Consider calling $obj->bar($obj) where obj implements IFaceA and not IfaceB, if $obj is of class A, this is ok, if $obj is of class B, this is invalid. In other terms, arguments' types should be contra-variant. Currently PHP expects them to be invariant, but there is already an RFC discussing how to extend it: https://wiki.php.net/rfc/prototype_checks Best, > > Julien.Pauli > -- Etienne Kneuss http://www.colder.ch --000e0cd1e24cf9ec5504b36cde2d--