Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97227 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 35393 invoked from network); 29 Nov 2016 17:40:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Nov 2016 17:40:17 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.210.171 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.210.171 mail-wj0-f171.google.com Received: from [209.85.210.171] ([209.85.210.171:36656] helo=mail-wj0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/62-20013-E7DBD385 for ; Tue, 29 Nov 2016 12:40:15 -0500 Received: by mail-wj0-f171.google.com with SMTP id qp4so152006008wjc.3 for ; Tue, 29 Nov 2016 09:40:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=reJ6TbCJnJvrl0DvP+LMDojkZi5GRk1nGLokwxsj1mY=; b=o7k8uHAkhlrw4NafPLiSgaNBW10WHMhvU3x5NzZ24QZLhtMRHllxyVkMHitrgxSOKM YaFNQ225iJX4URSxhAbBibiACUZjzzcY7QAPnOm5uCrdUgdKAfsv5SwQsgdTc8oeHakW lYAaA0liSZKwJkzk+71riphFutvlmdlnaFXLUyibt7VCunVzQRxFI6e+0t66YGqO4NdF M/2j/d2A326wi6SNXwnMvfiQHUwEZJYHb0e/YnBpmBqBVjdT7VdI93hukoz54q1xdr3W AvMpprmBFqeYpytLa6i4rp/GU6zm83cg+CkoW79b/vy4psQjNQxC0DbsPxymGlNIz3GC 7JCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=reJ6TbCJnJvrl0DvP+LMDojkZi5GRk1nGLokwxsj1mY=; b=R68zuSYDFxaDUK6CzxfJTz3czDaFXoC5iOgoh08lMJpX1IC+Uil2NOUYWP4sTusZOe eeVK3PpnbZ5dUN16oh7MbqiJiiH2S6ZNMZxex8VUJScXvid1C5VIiZUOgumSa8feR4Qe 0WOH+yCyUAURLUwuOvjzKea2Y5cRBS8el3LQAlVb6e/2UZw/e1Aar322dh88Mwpuhbw8 1IeAycQjbttwokL5eJ3WQW/Kywz4AK+2C48/BtgOKdjibh0lirGvmedgfcOzE63tEh5O Dj6KtOHK8kGFlF2gvKJq1ZXTm+dW6r6h5s62sn2USX3az+rSxhP0ouBwyH8IKnKkFUGv t0Jg== X-Gm-Message-State: AKaTC03wTyxg2G+K+sabLvUxzQGA5h7WZK5I5YZWbEtN8UmGrdlIgDsRtHulwqzyCDHudyV8Ld2S27ktnVD6Cg== X-Received: by 10.194.243.106 with SMTP id wx10mr29330576wjc.191.1480441211845; Tue, 29 Nov 2016 09:40:11 -0800 (PST) MIME-Version: 1.0 Received: by 10.80.145.7 with HTTP; Tue, 29 Nov 2016 09:40:11 -0800 (PST) In-Reply-To: References: Date: Tue, 29 Nov 2016 18:40:11 +0100 Message-ID: To: Niklas Keller Cc: PHP Internals Content-Type: multipart/alternative; boundary=089e014941448b02cb05427414a0 Subject: Re: [PHP-DEV] [RFC] Parameter No Type Variance From: nikita.ppv@gmail.com (Nikita Popov) --089e014941448b02cb05427414a0 Content-Type: text/plain; charset=UTF-8 On Mon, Nov 21, 2016 at 10:39 AM, Niklas Keller wrote: > Morning Internals, > > I'd like to announce a RFC to allow omitting the type declarations for > parameters in subclasses: > https://wiki.php.net/rfc/parameter-no-type-variance > > PHP doesn't currently allow variance for parameters as checking these for > compatibility isn't possible on compile time. > This limitation is caused by autoloading and doesn't allow widening the > accepted parameters. > > This RFC proposes to allow ommiting the type entirely in a subclass, as > dropping all parameter constraints is > always valid according to the LSP principle. > > We already allow return types being added in subclasses. > > Your feedback is welcome. :-) > > Regards, Niklas > The RFC is a bit lacking in motivation ... The main practical use-case I see for this is post-hoc addition of type-hints on an interface. To cite a particular example we ran into for PHP 7.0: Derick added a DateTimeZone type hint for the third arg of the DateTime::createFromFormat() method [1]. The method is already documented to accept only this class in the manual, but the typehint is not actually present in the implementation. However, this change had to be reverted, because all classes extending DateTime currently don't have this typehint (and adding it would be illegal under LSP), so they started throwing a method signature mismatch warning. Allowing extending classes to drop typehints in accordance with variance-rules allow people to add additional parameter typehints on parent classes without breaking BC. (Adding an additional return typehint would break BC, but it is still a cross-version compatible change, as consumers have the possibility of writing code that is valid under both versions -- something that is currently impossible if you want to add parameter typehints.) Thanks, Nikita [1]: https://github.com/php/php-src/commit/8e19705a93d785cd1ff8ba3a69699b00169fea47 --089e014941448b02cb05427414a0--