Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93284 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98370 invoked from network); 12 May 2016 17:03:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 May 2016 17:03:47 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.41 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.41 mail-wm0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:36829] helo=mail-wm0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B2/43-28272-277B4375 for ; Thu, 12 May 2016 13:03:46 -0400 Received: by mail-wm0-f41.google.com with SMTP id n129so267679897wmn.1 for ; Thu, 12 May 2016 10:03:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=n25tpkOtL6pd+Mx77vplqmYtU10XofAOCAYUe4PvwkE=; b=IyGovjAIH1fswrCjMHmgE2plwWGh2PM9IIeR7JM8ED4hXE9dPSWUjfdrE1fV1KpjkC Qsq/LMg1p5pDGy0ap+U2xltgP3UKSD4Y2Bl9k0BcHXYUNHniyFkpxp93OGeYIEkFwD3D qCgH5/BRT8UzERcl5rloUGQkz7Zc5FHxrNSdZrrVqFI0Ng+p9R7h+qf8mHoDHG2wQurg 9rlKS0poFT8MkW+i0agih8qFULAth7bGqbnWIBJSMqZwOxs51FROOKP9/kuk42J1yc1h mJBEjQmn14BPtgvrwetzTHDFG2GwpzA0L+0/9QlNPVa6J/jmSgZDgwG+FdABcsarBayo irqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=n25tpkOtL6pd+Mx77vplqmYtU10XofAOCAYUe4PvwkE=; b=a+aRUWXJ6+4EGOcYiwj9Qf0qliuE/2Tv0KGDhsATfKHUs7pJR+bwbKDgowy9BLQ2uv g33PduhnE4gIj7O8fP/Wd19XAHDIdbbq6CMltPrhV0tTxdNlmVIJ6Dn3Ho/mu4IdWA4U L/ZPlpujEuAyT8AUdBkgETX4yvfmpHIh4ITYwH6v1b5XInEmFidpFsH11MLJZLpVJe7N HJ+dGYF9QvsZfelz7kHxL9R0pzL5P8OesZTg24aKB1GrKdp2xSdWDXPnQPzUYQcJv6px upvShe4CD6M7d8fJtgdnzSghLOKhqjb8p4Wr/OvAgWTfoU2i6LvMY5N2o6n6EYuUjKle wnmA== X-Gm-Message-State: AOPr4FXXrBUTQLMKjFLYmACasuISCnKg7LejjDLQohv4OvJXP/torcFSv2nvKx2zC2IDUA== X-Received: by 10.194.216.33 with SMTP id on1mr11145686wjc.120.1463072624086; Thu, 12 May 2016 10:03:44 -0700 (PDT) Received: from [192.168.0.98] ([93.188.182.58]) by smtp.gmail.com with ESMTPSA id w9sm40446828wme.19.2016.05.12.10.03.43 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 12 May 2016 10:03:43 -0700 (PDT) To: internals@lists.php.net References: <5734B148.40602@mvlabs.it> Message-ID: <925076c8-5d9c-a780-c260-f1c76855283c@gmail.com> Date: Thu, 12 May 2016 18:02:13 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Functorial interfaces From: rowan.collins@gmail.com (Rowan Collins) On 12/05/2016 17:47, Andreas Heigl wrote: > It's the other way around. > > The interface creates a contract that ensures that you can use ALL > methods available in your SpecialClass. I don't think that's what the interface in the example means: interface Foo { public function foo(SpecialClass $object); } What this says is "an object adhering to interface Foo has a method foo which accepts any SpecialClass instance". In other words, it says that the following is bound to succeed: if ( $thing instanceOf Foo ) { $thing->foo( new SpecialClass ); } Marco is right that a class with a wider definition fulfils this contract: class Bar implements Foo { public function foo(BaseClass $object) { // do something with BaseClass $object } } $thing = new Bar; if ( $thing instanceOf Foo ) { $thing->foo( new SpecialClass ); } This is called "contravariance of parameters", and has come up a couple of times on the list. In particular, when return types were added, it was discussed that they should technically be covariant (subtypes can "narrow" return types, and say they only return a specific sub-type of the original contract). So from a design point of view, there is no reason not to support it; unfortunately, there are some technical hurdles to implementing that within the PHP engine. Here is a nice summary from Anthony Ferrara: http://marc.info/?l=php-internals&m=142791636808421&w=2 Regards, -- Rowan Collins [IMSoP]