Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103521 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6883 invoked from network); 28 Nov 2018 00:37:02 -0000 Received: from unknown (HELO mail-lf1-f42.google.com) (209.85.167.42) by pb1.pair.com with SMTP; 28 Nov 2018 00:37:02 -0000 Received: by mail-lf1-f42.google.com with SMTP id c16so17666955lfj.8 for ; Tue, 27 Nov 2018 13:00:45 -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=hcMKOOatR6f1E1Eu71se9nB92tIjYGZiLOzWrCONoVE=; b=DBkg1SaMMUWY3QKWBJ+hx73HKPHp1csDA+etNd8NjEqbqnY8gHn96zm/xjJaUSs9JZ gMirmBV9GyyTsxLDIxT7Bup6m8gaW2KSMf9EmXE6DerY6oa4dQ3TpKoD4cvncaiq9Lhm D6WLSobxWYxNyYXzFeBtgMGMKKif2x2t3S0enJ/BeG/1ilwKljTN1FrRGm1m0YW8VNty F2hYbq+QGNiwvZO3A0H3evy4gYZ9SpTh+Lvu3AviFjRwomA/2jdaLjoBNkm1vGkCAnLn AxnoklJcQFbxHUoADkYwgKcHtwLuW/jMxRh8+cw/pPzIsC5VsXxYoMkbqt/XjRhLkLq1 xfbQ== X-Gm-Message-State: AGRZ1gIKW+3DwT4Xz2e76lL9cbFyIpN1ZsxgCk9En4ch7t2FW6CjxrtU ZQI0P2up9sCAP1S2BN1qoCnOPxqTL5MQpcDv2Rz3HQ== X-Google-Smtp-Source: AJdET5fu1Wr9hnneAEdgw7YbUQC6S/T3O7TvvbhTiK2yy7Pq8VaOb4yd9VS9RKOaFLJDP6oKdVljzxAqkpNjiH1QP+I= X-Received: by 2002:a19:1cd3:: with SMTP id c202mr20689275lfc.33.1543352444395; Tue, 27 Nov 2018 13:00:44 -0800 (PST) MIME-Version: 1.0 References: <2701692.XuXcyRlYA4@vulcan> In-Reply-To: <2701692.XuXcyRlYA4@vulcan> Date: Tue, 27 Nov 2018 14:00:27 -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 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.