On Wed, Dec 12, 2018 at 4:25 AM Christoph M. Becker <cmbecke...@gmx.de> wrote:
>
> On 11.12.2018 at 21:34, Levi Morrison wrote:
>
> > On Mon, Nov 26, 2018 at 2:25 PM Levi Morrison <le...@php.net> 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. […]
> >>
> >>   [1]: 
> >> https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters
> >>   [2]: 
> >> https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters#examples
> >
> > It has been two weeks now. If you want to provide any feedback, or
> > follow-up on anything from the discussion, please do so soon. I hope
> > to put this to vote before the end of the year.
>
> Thanks for working on this, Levi.  Highly appreciated!
>
> I may have missed this, but otherwise I'd be quite surprised that nobody
> had commented on:
>
> | Therefore, by-reference parameters are still contravariant, […]
>
> Call-by-reference is not seldom used to provide out-parameters, but
> these should not be contravariant according to LSP.  Therefore, it might
> be best to keep by-reference parameters invariant.
>
> --
> Christoph M. Becker

Christoph, we cannot make any guarantees about the type of the
variable when the function returns because the type of the parameter
is only checked on function entry, and not also on function exit, e.g.

    function array_baz(array &$in) {
      $in = 1;
    }
    $array = [];
    array_baz($array); // valid
    var_export($array); // 1

I do think we ought to have "out" parameters some day which would
prevent this behavior (as well as have some other benefits), but that
is out of scope for this RFC. The RFC notes that if we had "inout"
parameters that they would need to be invariant. It also says that
"out" parameters would be invariant, but they may be covariant
depending on the exact semantics specified -- all that can be handled
in the RFC that proposes it.

I will add this example (or maybe a better one) to the RFC. Thanks for
bringing it up.

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to