Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78789 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 87548 invoked from network); 6 Nov 2014 07:43:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Nov 2014 07:43:19 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.218.46 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.218.46 mail-oi0-f46.google.com Received: from [209.85.218.46] ([209.85.218.46:50855] helo=mail-oi0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/8A-28384-6962B545 for ; Thu, 06 Nov 2014 02:43:19 -0500 Received: by mail-oi0-f46.google.com with SMTP id g201so366961oib.19 for ; Wed, 05 Nov 2014 23:43:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=f921jQBUxXU1OXYkMktMM2EFu+vujIqD5kGg3CxPxxk=; b=jBDuzLUOMLNOOP+2TbcGzqXDZPv9eYFE5RfI3vxADKGGCIVd6b0LlS2HEBuEIwrRBZ ivlAPE4lsRTILi4Nm5+dAoJRh9oOkWO8bVUJPRjE3MtMDNEsjWbYkOCP4Pz0rIjA2o+p 7knVv2JdexVspxaEhvs2EeHZovEEWQ18V69CmEFUYN9xhbC1XKrT+bHhp1G+shvr94+S yAgVvL7OyjNzN8CCvu+HF0rEovuyeYTXChziBwlt8W76TeTp8t26sr0zuRSWtmJ8dKa4 4F6S0+FYW2dD+MHWsUdsQcelnoN7BFV7K939LIOuK5skQWLKyX9vBb7SjlYJL817x5dl KvkA== X-Gm-Message-State: ALoCoQm3gNR0dzLAzcPspZRlwmj1N9RnMBZs55A4Y976TkZVeLrY1zhLvwAbQlbRYUlOktVOdQjDYW0FrVVWINbeK0qwpqLNvB+p8BP3yrUwEXyzJQ3eiG3Cpzgt+NB6RJk+JiSE4vmiIVFbfB/iyr2Z3dwc0BHLkg== MIME-Version: 1.0 X-Received: by 10.182.20.112 with SMTP id m16mr2248235obe.25.1415259796466; Wed, 05 Nov 2014 23:43:16 -0800 (PST) Received: by 10.60.70.41 with HTTP; Wed, 5 Nov 2014 23:43:16 -0800 (PST) In-Reply-To: References: <5B1B375C-328B-40BD-B715-8EDA158B44CE@ajf.me> <545A912A.2050202@sugarcrm.com> <545AA193.6060606@sugarcrm.com> <3E396F3F-CD59-4198-8FD2-1A8C4ED3B87A@ajf.me> <5BB43ECD-089D-4DDD-AD95-1263B05279CB@ajf.me> Date: Thu, 6 Nov 2014 11:43:16 +0400 Message-ID: To: Levi Morrison Cc: Andrea Faulds , Stas Malyshev , internals , Nikita Popov Content-Type: multipart/alternative; boundary=001a113319bc6f0a9605072bd9e7 Subject: Re: [PHP-DEV] [RFC][Vote] Return Types From: dmitry@zend.com (Dmitry Stogov) --001a113319bc6f0a9605072bd9e7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable It's clear, that covariant types are more smart, but not supporting them, won't prevent access to more specific type properties and methods. We are not C++ or Java, and we don't need to cast objects to more specific types. On the other hand covariance requires all return types to be defined before class binding. It may be a serious new problem. For example you won't be able to compile the following code at all? The similar code with argument type hinting works fine. It's just a first example I could imagine, I believe, we will get more... Thanks. Dmitry. On Thu, Nov 6, 2014 at 5:01 AM, Levi Morrison wrote: > To demonstrate the value of covariance and why `static` alone is not > sufficient, here is a small example: > > interface Enumerable extends \IteratorAggregate { > function getIterator(): Enumerator; > } > > class Vector implements Enumerable, \ArrayAccess, \Countable { > function getIterator(): VectorEnumerator { /* =E2=80=A6 */ } > } > > class VectorEnumerator implements Enumerator, \Countable { > /* =E2=80=A6 */ > } > > This shows why covariance is important for two reasons: > First, it shows that static isn't sufficient. The VectorEnumerator is > not the calling class, so self and static are not applicable. > Second, without covariance you could only declare a return type of > Enumerator for Vector::getIterator(); a calling class couldn't rely on > the properties of a VectorEnumerator that are unique to it, such as > \Countable. > --001a113319bc6f0a9605072bd9e7--