Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103523 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11724 invoked from network); 28 Nov 2018 00:51:18 -0000 Received: from unknown (HELO mail-lf1-f42.google.com) (209.85.167.42) by pb1.pair.com with SMTP; 28 Nov 2018 00:51:18 -0000 Received: by mail-lf1-f42.google.com with SMTP id e26so17701529lfc.2 for ; Tue, 27 Nov 2018 13:15:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7e8emA8wI+YZnpbxIHztCZcFtauweBN5vbLTeCc/3bA=; b=GpYj5QOmfnV4KhfWEhXlewQ6DK/jKDi3DfZu2vY9xkExRQreIvt/3H3R7h00SrUokX VddiylFWZ1p0WCCL3mgi5IWCB45myuupQdRAbCx/zj64/iqGFuRGmc7mvmc45e734mwk ZmEogIwS0+HykNrZVbrj9xWixzsVTC2xHK20q0TUfRmiThwcFopgDxVGCEItfBE2HpuC z03Fkr8GvprRW/s2Ttj9TMFDkrN+kieDX8hLrZxXLiLAQN4QsMUMO3+d5LEvB11Sh3mF rToANddjuwDfohLkjciHvtW2SYC/VRHyTbl4H+jh3/H44dUnJVy9UaU6oQ99xF3iITZt RC0A== X-Gm-Message-State: AA+aEWa8wxIMIIUFnqHtOVJk8AKJKWi4AhT8e2lAmRcU/OTJPZiEniI5 CtUBfopewuF0EUkaBDu346dQ19yEvOFuEgrv5PQ= X-Google-Smtp-Source: AFSGD/UlKsLp3+0/QHsBLj+OMvxDVQpwObIjFnTC0HlpYYs5nlPpA1UoFGGqiwm7IKn26yYwxL4PAtuEDjS+TmAr0s8= X-Received: by 2002:a19:6806:: with SMTP id d6mr4782702lfc.48.1543353300826; Tue, 27 Nov 2018 13:15:00 -0800 (PST) MIME-Version: 1.0 References: <2701692.XuXcyRlYA4@vulcan> In-Reply-To: Date: Tue, 27 Nov 2018 14:14:43 -0700 Message-ID: To: Larry Garfield Cc: internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC][Discuss] Covariant return- and contravariant parameter- types From: levim@php.net (Levi Morrison) On Tue, Nov 27, 2018 at 2:00 PM Levi Morrison wrote: > > On Tue, Nov 27, 2018 at 11:36 AM Larry Garfield wrote: > > > > On Monday, November 26, 2018 3:25:52 PM CST Levi Morrison wrote: > > > I am happy to announce my latest RFC, [Covariant Returns and > > > Contravariant Parameters][1], is open for discussion. If you do not > > > recognize those terms then hopefully the introduction coupled with the > > > [examples][2] will help. Here is one snippet that demonstrates > > > covariant return types: > > > > > > > > interface Repository { > > > function fetch(int $id): ?Entity; > > > } > > > > > > class UserFactory implements Repository { > > > function fetch(int $id): ?UserEntity { > > > /* Since UserEntity is an Entity, this is now allowed */ > > > /* ... implementation ... */ > > > } > > > } > > > ?> > > > > > > Covariant return types and contravariant parameter types are highly > > > requested features; here are a few of the bug reports: > > > > > > * https://bugs.php.net/bug.php?id=71825 > > > * https://bugs.php.net/bug.php?id=72442 > > > * https://bugs.php.net/bug.php?id=75385 > > > * https://bugs.php.net/bug.php?id=75823 > > > > > > There is a [preliminary implementation][3] that is available. It will > > > not be rebased during discussion to allow people to check out the code > > > and get updates without worrying about it breaking. The code quality > > > can definitely be improved, and there are still a few todo comments in > > > the code. > > > > > > Please do not discuss the items found in [Future Scope][4] as part of > > > this thread, which includes discussing types such as `mixed`, > > > `scalar`, `numeric`, etc. > > > > > > I look forward to your feedback, and especially with your > > > experimentation with the implementation. > > > > > > Levi Morrison > > > > > > [1]: > > > https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters > > > [2]: > > > https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters#exa > > > mples [3]: > > > https://github.com/php/php-src/compare/master...morrisonlevi:variance2 [4]: > > > https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters#fut > > > ure_scope > > > > Looks like fun! > > > > Would this also include allowing a return type of `static`, which would be > > useful for the "Return the object that was invoked" case or "return a new > > instance of the same object" case? Currently we're limited to `return self`, > > which is, of course, not the same thing and less flexible. > > > > --Larry Garfield > > It does not. To be honest, I did not think of it until your question. After thinking about it, I believe it is out of scope for this RFC. While `static` would be covariant, it's also more than that. Accordingly, it deserves to have its own consideration and voting.