Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79214 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67145 invoked from network); 27 Nov 2014 07:48:35 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Nov 2014 07:48:35 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.180 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.192.180 mail-pd0-f180.google.com Received: from [209.85.192.180] ([209.85.192.180:45518] helo=mail-pd0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/33-40216-257D6745 for ; Thu, 27 Nov 2014 02:48:35 -0500 Received: by mail-pd0-f180.google.com with SMTP id p10so4440901pdj.39 for ; Wed, 26 Nov 2014 23:48:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=gYgZG1v8fT5bkZl9ADLfbpkkwQ0BUJi59IVwxOjPJrY=; b=hMhr1XszjY0YLpcFMhk8Bu71CTax7Hfo4OOu48PyMtexBmz9CvFuujtZfg4eOmuBp4 8uiJr2plGchSFwIzH9RRHviT4OtqpGis2HOE5eXu9WMInZGHjAV8piHWgM0YCBnTwklU Vp8rUTOXxpkp7vKTB9RMPi8cFnAwyyuBFUuV/hC3JGeJ+4UQEMTMYZvHJP1SDPG258YZ tuxGi1Dgw7UdqAYq9YXsyf32J5Na4F9ZZV4pEJ7+54WxpzpPTQ1YCT+HnKEBiZpQSNjv 8+hCO2iimWBvO4vt8sIoE0GiEc8agpj1zG3bZSudUODOotkybDq3O1jwKmfi5rfwpdMf rR0Q== X-Received: by 10.66.119.105 with SMTP id kt9mr60139860pab.113.1417074511844; Wed, 26 Nov 2014 23:48:31 -0800 (PST) Received: from stas-air.attlocal.net (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id g8sm6240180pdn.80.2014.11.26.23.48.30 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Nov 2014 23:48:31 -0800 (PST) Message-ID: <5476D74D.4080507@gmail.com> Date: Wed, 26 Nov 2014 23:48:29 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Marc Bennewitz , internals@lists.php.net References: <5474EF98.8070602@mabe.berlin> <5474FF0C.4010405@mabe.berlin> <54750074.2000800@mabe.berlin> In-Reply-To: <54750074.2000800@mabe.berlin> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][Discussion] Return Type Variance Checking From: smalyshev@gmail.com (Stanislav Malyshev) Hi! >> class FooFactory { >> function create(Foo $foo): Foo { return $foo; } >> } >> >> class GooFactory extends FooFactory { >> function create(Goo $goo): Goo { return $goo; } >> } > OK HHVM allows it - we also allow it but trigger an E_STRICT error > @see http://3v4l.org/UhtOb This is because this code has LSP violation - if you have an object about which you know it's typed as FooFactory, you should be able to call it with any Foo object. But if this object is a GooFactory instead, now not any Foo would serve, but only a subset of them - namely, Goo. This clearly violates the principle "everything good for the parent must be good for the child". Since PHP is a kind and nurturing language, we only produce E_STRICT, some other languages would refuse to accept such thing or interpret it as two different methods. See also: https://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)#Covariant_method_argument_type -- Stas Malyshev smalyshev@gmail.com