Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:99214 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46013 invoked from network); 28 May 2017 13:25:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 May 2017 13:25:14 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 74.125.83.50 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 74.125.83.50 mail-pg0-f50.google.com Received: from [74.125.83.50] ([74.125.83.50:36847] helo=mail-pg0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F9/54-06590-8BFCA295 for ; Sun, 28 May 2017 09:25:13 -0400 Received: by mail-pg0-f50.google.com with SMTP id x64so12048301pgd.3 for ; Sun, 28 May 2017 06:25:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mindplay-dk.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=wnYOWgECwHzHRn3f9KhCAct04Hf5h2oxFRq4Ijcuz5E=; b=0Hjhzh0IWLtETRgGE4W2TcURJzoiU5joxF9QZHtiJXeiCt4vy2SUOd9FMGZ7xjV2gY jPpFuiRo9HTA7PTDKwMw9xKk02lMZavQQPgO29t271FSJ2e/66F6Cf9+IWWU7mS3s+RZ 35QhWbCjjzgurwnkyRaUddbMKf4MIJt6z6oiGm3bgrOnzRYhX8D30IfMt+n35cc0dqtQ xwQUAysPUqgiFw6lMhchrzG7EKCNNMQgGWpxkjyl9Fd8SPtV+ELNIqs+LXdHjFhn2f1W 5ucQKtC306BC2GWkfBe7ZEj/f5t8yTt1EoOjXeWgwpHs6pmJsSUA/dkP/rr+C3nOPlJo eFWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=wnYOWgECwHzHRn3f9KhCAct04Hf5h2oxFRq4Ijcuz5E=; b=S/IB4qien+/91h2zAl0KvhgYdY9A3C5C0zkd8h18atWJO5ccHain6eVYCyZycN+NV0 ug8e1kUfjmoHPWZUNk3oK28Dpp8PhJ5sihO3YJS5cekkbaUvxZ9d8Y2AKSFgVJaFx9pn jOOiagVHox+UoyIFjt5XWxoruASsl+KYugZ9vLg6brbb5icbiO/XuvvP7LxMYlK8mxwR ZJd8CZV7aumxQHACVVY6WrugQPF95Ac2y5ivZIf6ND7Gxbl314HN8dw/JFPL6K2uR1fF nomoU0QHZeqgHUyYMAJbbJq56WQ6M8eQqgXJOL8CLNgnw1quFWFx8sFZjiM5I67LD5A3 5+qQ== X-Gm-Message-State: AODbwcBJfkAYi6wyeaujJhw3RO7+qQiR9Mwe6BsYomRS/TABHKeOXYWE x7dRnhJ9Xei7SK+XbU7ButfdtSVzZ5PQ X-Received: by 10.98.149.68 with SMTP id p65mr12591780pfd.206.1495977910031; Sun, 28 May 2017 06:25:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.100.131.23 with HTTP; Sun, 28 May 2017 06:25:09 -0700 (PDT) In-Reply-To: References: Date: Sun, 28 May 2017 15:25:09 +0200 Message-ID: To: Niklas Keller Cc: Dan Ackroyd , PHP internals Content-Type: multipart/alternative; boundary="94eb2c0069c4eb6e180550957f63" Subject: Re: [PHP-DEV] Parameter type widening RFC From: rasmus@mindplay.dk (Rasmus Schultz) --94eb2c0069c4eb6e180550957f63 Content-Type: text/plain; charset="UTF-8" Alright, here's an example of code where a type-hint was accidentally left out. Before this change: https://gist.github.com/mindplay-dk/e988902ed2d587dc05a1d8cb164b88c4/4d03babff16883a67accfb51b50e3d1aefb13a8a And after this change: https://gist.github.com/mindplay-dk/e988902ed2d587dc05a1d8cb164b88c4/03a4eec05b64185830785c5e684b3f94c1d62f5e In other words, accidental omission of type-hints now means that this faulty implementation is valid code. And hopefully something will error, deep inside a call-stack, maybe in a database-component that performs a type-check or something, but there is no guarantee that it will error at all - if you passed an object that does have a getID() method, because there's actually no type-check for the Identity interface when calling the implementation, worst case, it actually executes and quietly saves *something* to the database. > No, interfaces exist to guarantee the caller can always pass a type XY there. > With type constraints removed in a subclass, this guarantee does not break. No, but you no longer get a type-check. So yes, for *correct* code, there is no problem - but if you didn't write the code correctly the first time, with this change, you may never even know you've done something wrong, or you may have to drill through a much larger call-stack and try to derive the source of the problem. Before this change, a faulty implementation would simply get rejected. To me, that's a setback that leads to harder-to-debug errors, and increases learning-curve. With an explicit mixed type-hint, you can still achieve what you want in those rare cases where this simplified kind of contravariance is actually useful, without also creating new problem cases for everyday coding. On Sun, May 28, 2017 at 2:27 PM, Niklas Keller wrote: > 2017-05-28 12:30 GMT+02:00 Rasmus Schultz : > >> > > So this breaks the expected behavior of interfaces. >> > >> > No it doesn't. It allows interfaces to use contravariance within PHP's >> > type system, which is different from before, but it doesn't break >> > anything. >> >> The RFC explicitly states that this is *not* contravariance. >> > > Where does it state that? (The "true" in the future scope section should > probably be replaced with "full".) > > >> And if it's not clear, what I mean by "breaks the expected behavior", is, >> as far as I understand, what this RFC actually does is it *removes* >> expected behavior. >> > > How does this *remove* expected behavior? Could you show a concrete > example of code that breaks? > > >> Correct me if I'm wrong, but really all this RFC does, is remove the >> requirement that and implementation of an interface be type-hinted? >> > > Correct, but not just for interfaces. > > >> To me, that's "broken". >> > > As said, please show a concrete example that breaks. > > >> You're favorizing a very, very small number of isolated, valid use-cases - >> by removing the normal, natural, expected constraint that an >> implementation >> be type-hinted as specified by the interface. It's part of the reason >> interfaces even exist - and this simply ignores that and removes these >> checks. >> > > No, interfaces exist to guarantee the caller can always pass a type XY > there. With type constraints removed in a subclass, this guarantee does not > break. > > >> In my opinion, this will very likely lead to a large number of accidental >> type-hint omissions - and a very, very small number of actually useful >> solutions to real problems. >> >> In my opinion, we can do much better than that, by adding a mixed >> type-hint, which will ensure people aren't just accidentally omitting >> type-hints and instead explicitly opting out of it to achieve parameter >> widening. Solving this from the start also ensures we can have a clean >> implementation of real contravariance in the future, without that being a >> break change. > > > You're, again, ignoring one of the major benefits of the RFC: Being able > to move from explicit type checks to type declarations without breaking > subclasses. > > >> > Rasmus, not answering people's questions and instead saying emotional >> > stuff suggesting other people have made historically bad decisions >> > isn't a productive way to conduct a conversation. >> >> Okay, I'm emotional, sorry about that. >> >> But I think I'm pointing out a real problem and a real possible solution >> that doesn't make the trade-offs of the current solution. >> > > You haven't pointed out a real problem, yet. > > Regards, Niklas > --94eb2c0069c4eb6e180550957f63--