Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103547 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 16094 invoked from network); 3 Dec 2018 20:20:06 -0000 Received: from unknown (HELO mail-lj1-f171.google.com) (209.85.208.171) by pb1.pair.com with SMTP; 3 Dec 2018 20:20:06 -0000 Received: by mail-lj1-f171.google.com with SMTP id l15-v6so12028527lja.9 for ; Mon, 03 Dec 2018 08:45:16 -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; bh=qcObitbw7pM7SQrDloAyIirLgkNd3pC/0iX2SuMJA+8=; b=eaikyptNjehh4Lpg3rxKfjjVe8sXJ20HGUuSeSh2CikoY9EZudzYzG9hLgtTAOeij5 DmRRP4UD2t6eBR9AIu8oZFb/ziHmK71x5amLK9LRU9NCTBzhesdA9Dytolb8C94/Lzs1 6rKA9CCeh86B3/uq2gGT55T5Vx7ydrcTsLSV4IyO9n6knBzq5ZRZ14qFihWmsrVU4m7d c8b62ZWY0Ytltu8m90MJZsi8tZxC9EWqpA8l1hyFBB9art6MNIaMBrX8A+sDNaxgZ4Hw k1oT+mCYnKJehEnGIIISnXEvZ7715AVJroMfdcW/il4t4tRSbBpF0UxKbcxQZrghGfAd Q8TQ== X-Gm-Message-State: AA+aEWbV5fH95/vQmM30420FrJrIFDeC6/ivEQZR40LvaZf1lthSGNcO P+k6jlt/9BOendMN3sMLqvh4oOLh+1A1EPooawdGmZZ/ X-Google-Smtp-Source: AFSGD/UwN5W4mGMR0TCRJCq7DIE+w+kMn49de0TKV1daCASI4Nl606kzZIz92oxchFfokJHNUa9oH4WJRKnF1JeCipM= X-Received: by 2002:a2e:4218:: with SMTP id p24-v6mr10515144lja.58.1543855515497; Mon, 03 Dec 2018 08:45:15 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 3 Dec 2018 09:44:58 -0700 Message-ID: To: internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [RFC][Discuss] Covariant return- and contravariant parameter- types From: levim@php.net (Levi Morrison) On Mon, Nov 26, 2018 at 2:25 PM 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#examples > [3]: https://github.com/php/php-src/compare/master...morrisonlevi:variance2 > [4]: https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters#future_scope Our existing engine doesn't always resolve "parent" at compile time when possible. As part of this patch "parent" is resolved at compile-time when possible and warnings and/or errors are emitted in certain cases where there were none before. For instance, this would only cause an error only if the method `C::m` were to be used: This now emits an E_DEPRECATED warning when C is compiled. In 8.0 this should be elevated to a COMPILE_ERROR. The current edition of the RFC fails to mention this.