Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108006 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78645 invoked from network); 6 Jan 2020 13:12:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Jan 2020 13:12:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AEDA11801FD for ; Mon, 6 Jan 2020 03:17:16 -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-f173.google.com (mail-lj1-f173.google.com [209.85.208.173]) (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 03:17:16 -0800 (PST) Received: by mail-lj1-f173.google.com with SMTP id y4so36194329ljj.9 for ; Mon, 06 Jan 2020 03:17:16 -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=L3n/3vhqzHDEWmI2dwFpFybct2HYkI41eO44EZzd71I=; b=VrwPzCu1cVFCEtIFiuTO0g0aJgW4RuMXRdvdMibgIkHFF6KU9YvA56VBwXRIzNzMb/ dsGHEQ8iS7/2qyaUOZXTAd93vTG0sMJLVKUG/RfmcyDtby+pnAxFHWNDg4Cc1JP1l4WT zNgQVRZqMHPwfsomo1Jb8B9F0V1CxNct8YUFkRhsGCuGGvPh51h/2IUFRHzvuFqOO3Pf 1F60SjhpD+pvY2GPvu60KogiDV7c3ZidOEki9aDe/+YO6zJThvGb5KbLEa2oAk5I3hCF 1wauaNiJxBuQz/aB21Tl4ECQ77uFIjdLpaUkmsve7erLEwiSD5qDYdAq4CILx1lWIUHx 8XwQ== 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=L3n/3vhqzHDEWmI2dwFpFybct2HYkI41eO44EZzd71I=; b=LOxGuwydJNpDV4gSHE07SURb8vi6t8UVNca9Uj+k29ChwPXPeo653o3pBiMLUmzjHQ LidRobLRtVCi3lEVqrwYY9F5NPvH3XhdKx+2Oeb1Zw4fbZt/BYuhrf0oup1daR0bhnxf Jg6jCcIfMWo71U2h/TD52tqiJIUr+fw0gxqVj+PEI89zfB2/KQxNm3lL0kUrsflpWlE5 E1PX4WazrKeVhaO4QtqQN67zn2aIdtRZInPOLgIi0o/K+Lf/Fbn0+vQZTLO4kYi+ijuu PwLFekDSnqNIZ6nDkrfQOtRw5xOZsQeB9diGzKM03XIQzfjuVOre//AxmBK7GjpXAEZ6 tzWQ== X-Gm-Message-State: APjAAAW8VvMFQ1XNbuuse4FZ7miWS2TUyZjYnC36WLgEZVMVmxKMC81g awgHyIumy7H1XcCk+Zpb5JOJpewpvKCnnbQp1nMLB7k58vE= X-Google-Smtp-Source: APXvYqzx1ffjbknPNUcWpD21axZrgpYcmJ0fIs/+NsmEMMEwXERKSZSkjS7yLavyWkV82UHaLB5xmtZmcX2t6ceKVlA= X-Received: by 2002:a2e:9d89:: with SMTP id c9mr44798656ljj.129.1578309432406; Mon, 06 Jan 2020 03:17:12 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 6 Jan 2020 12:16:56 +0100 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000001074b9059b76cdac" Subject: Re: [PHP-DEV] Inconsistent class behavior and undocumented(?) BC change From: nikita.ppv@gmail.com (Nikita Popov) --0000000000001074b9059b76cdac Content-Type: text/plain; charset="UTF-8" On Sun, Dec 8, 2019 at 1:29 AM Larry Garfield wrote: > I am not sure if this is a bug, a feature behaving in a desired but > confusing way, or a feature behaving in a confusing and thus undesireable > way. I am therefore reporting it here in order to defer to those who know > the answer to such questions better. > > Consider the following: > > class Ancestor { > public function __construct(int $a, string $b) { } > } > > class Child extends Ancestor { > public function __construct(...$args) { > parent::__construct(...$args); > } > } > > This works with no compile errors. For any other method however: > > class Ancestor { > public function doStuff(int $a, string $b) { } > } > > class Child extends Ancestor { > public function doStuff(...$args) { > parent::doStuff(...$args); > } > } > > I get: > > Warning: Declaration of Child::doStuff(...$args) should be compatible with > Ancestor::doStuff(int $a, string $b) > > I am not clear on why __construct() is special in this case; I know > __construct() is special where interfaces are concerned, but I didn't > realize it was special with regards to basic inheritance. It seems to > happen regardless of the type information presented (or not). > > Is this intentional? Is there a logical way it could be made to work? > Are constructors actually wrong here? (I hope not, because it's a neat > trick.) > 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 --0000000000001074b9059b76cdac--