Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108010 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 52677 invoked from network); 6 Jan 2020 20:35:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2020 20:35:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5528B180540 for ; Mon, 6 Jan 2020 10:40:21 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 6 Jan 2020 10:40:20 -0800 (PST) Received: by mail-lj1-f170.google.com with SMTP id h23so51972281ljc.8 for ; Mon, 06 Jan 2020 10:40:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=roN+Kb5/KSYDaxaMHaPpKfuMepmTk1ZI+tnQW8bJdto=; b=TizpsyZOplhixxusoh5jTHSvm4TrW+WXEyhMMNCosfL3NPtSx2ogmnn8ccUlVnuxpU gPwCR9pbe3ULPjjT+yP7NkzH4yrGyf7yINgqnUGQzYfEXu9dWkP80wo+doTcz3CsbeKC 0CycOxHLToYJRT4fgJyP6o+ldVLeenXh0AkqlPqnk9kDAg5W78w4lIvlaZvtTXeu+80f IVZ4O7BOl/P55G2rcma3PUttyDP8i51eW2Yg5cvjVSlZh4Vz3Q3KUyOqwXpKt9ZIUu/3 VyegFT3pcLYJxeOO0LbnF9I8Cs/HT1eYKWW3zR/q6vVP2YecT83traLMqAUT56Bu7LC1 b3Eg== 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=roN+Kb5/KSYDaxaMHaPpKfuMepmTk1ZI+tnQW8bJdto=; b=tXXQihJN4w4MNTj/JL6Tor2kboY6FR48FskrB6m/hSidSDdtZP61ZBEHjsC7Zb2nQQ b/NN0AXwkmmvi+Zv5MKan57gTIfoFNi17IpbtbcrRZqSLW4gGtBa+OWaMDFoFCzpP6T0 wjqwC16QkBNreFTFJQyPtcEHvvVGmuLqlUiBq94DhftkQTRTkhcOhSXpo7f+w+CC2jBv 5rq+JKvnjcX6IoY8YHeUgvuDt6o48ZF+Df135luiP+Hq7nXzOtzIidyg0/Wyxoau7Iwy EbieOP7TeF14MFHZyXsoEVlUJsuGIej7CNtFnhXQkigbuHS4I5wGoYvEYi4XYdKMfbSB b2BA== X-Gm-Message-State: APjAAAXXCkGFWOuoGETbUt8Vqpr0iiTIFuIFirk9b3TmgyZpDfBGcScK Qd1DbF3bq9KysIY7FzHPoWhyQM9jxgg8V/PU93Akqyghkfs= X-Google-Smtp-Source: APXvYqzYBJMDdkco3IOoTB5gJpIFaIBfrJYQvDrzjnayhGLzU5c142TAwpvyM10iFIvgzWyf1uvJV2TSGxzILU5JIyA= X-Received: by 2002:a2e:5304:: with SMTP id h4mr63261534ljb.75.1578336018416; Mon, 06 Jan 2020 10:40:18 -0800 (PST) MIME-Version: 1.0 References: <9126e194-fee1-4d54-968c-d964d2e442f3@www.fastmail.com> In-Reply-To: <9126e194-fee1-4d54-968c-d964d2e442f3@www.fastmail.com> Date: Mon, 6 Jan 2020 19:40:01 +0100 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000b6c79f059b7cfd2f" Subject: Re: [PHP-DEV] Inconsistent class behavior and undocumented(?) BC change From: nikita.ppv@gmail.com (Nikita Popov) --000000000000b6c79f059b7cfd2f Content-Type: text/plain; charset="UTF-8" On Mon, Jan 6, 2020 at 7:18 PM Larry Garfield wrote: > On Mon, Jan 6, 2020, at 5:16 AM, Nikita Popov wrote: > > > Others have already explained why constructors are exempted from LSP > > checks, so let me reply to your other point... > > > > I believe that your example should indeed be legal in general and > created a > > PR to fix this: https://github.com/php/php-src/pull/5059 > > > > With this change, the variadic argument can replace any number of > > non-variadic arguments, as long as it is compatible with them, where > > compatibility is, as usual, determined based on type contravariance, as > > well as reference passing invariance. Effectively this means that > > function(...$args) is compatible with all signatures that do not involve > > reference passing. > > > > Does anyone see any soundness issues with this change? > > > > Nikita > > Nifty! Since `func(...$args)` is already a universal caller, that gives > us a symmetrical way to defer calls, either to a parent or to a delegated > method on a wrapped object. So that means one can implement a pass-through > class where most of the methods are: > > class Wrapper implements Thing { > public function thing(...$args) { $this->wrapped->thing(...$args); } > } > > The symmetry appeals to me, even if it means types get caught only at the > lower level. > > One possible question; would this mean bypassing type checks if not > delegating? Viz: > > interface Foo { > public function bar(Foo, $f, Baz $b, Beep $e); > } > > class Impl implements Foo { > > public function bar(...$args) { ... } > > } > > $i = new Impl(); > > // Will this still report a type error, and if so, where/how? > // If not, does that become a back-door way to dodge an interface? Is > that good? > $i->bar('a', 'b', 'c'); > Yes, you can "bypass" type checks that way. However, this is not related to variadics, but general contravariance. In particular, you can also simply drop the types while keeping the explicit parameters: class Impl implements Foo { public function bar($f, $b, $e) { ... } } As of PHP 7.2 (I think) dropping parameter types is always allowed. Nikita --000000000000b6c79f059b7cfd2f--