Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102228 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83859 invoked from network); 11 Jun 2018 14:12:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jun 2018 14:12:25 -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 209.85.192.178 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.192.178 mail-pf0-f178.google.com Received: from [209.85.192.178] ([209.85.192.178:34242] helo=mail-pf0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 06/DE-62758-8438E1B5 for ; Mon, 11 Jun 2018 10:12:25 -0400 Received: by mail-pf0-f178.google.com with SMTP id a63-v6so10310037pfl.1 for ; Mon, 11 Jun 2018 07:12:24 -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=xO70X/ynCbA75qGHT2TWVXC4yUMeVIPK33U8hetchLs=; b=E0JI9X2QiCyw9hQ0eVTpX9iPRvrXofOf1pp8dmDx3elFaFQ6mZ0+m9eJ+Sw4yle3Ah eOIyggMy/rst2CEDpgIXZkX3AEnOzpy64hmEcbB1Ag4T/4jdrhfpRwntdNF/aeijgjpS ePOWKnpyV/WJHC5Y3tFG/40Ewf8YaPonXuYbGDCVj8bMKrNFBYPhDojUAS6tt5BbhwgC RTwcUfIgsk+DYIyTI69EerZWhQ4UgtxJSNcF+gEVoX0EEsFkLHc4wOdjtnQ7lk+HBw5S ROiIPXAuXDUcv1nCOIwZNaok8J9Jrqbh+qnn1kh95MMJH8VjZ1WrB3TjJ/0jGs7SrQIA dzkQ== 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=xO70X/ynCbA75qGHT2TWVXC4yUMeVIPK33U8hetchLs=; b=Z6qvjfOY4bkKRWplMLFRuYDdhdTVs0a2qsNi0pf9dNREjT5vMMttYgnL6cHafy3ia6 Bz8dMk8we7UgawiWooqD0VRSq5dp+4QlQTf0yReo8JTMLVzTDDcnr5AN9h+DTK35POV6 F+QOu2C98CatpH6OzCBZVc3ZvR2pvDByZ372SeeHjyL6yINktXtxpfMNPNXDAlrtFz9p bFq+PhWPpWzMDfc5GVYEFb+dVbD1ZUp/o8puKmb807PAUMo0ubR/ewVtpn9+AeC0POkO dwtCvpfQeqE4mnq3rkm32rfKZojcmnXQ1NpgTKQTOokNgQFI87pkeB/AYZCTtqVGU0vM xZVQ== X-Gm-Message-State: APt69E2m1ftJKy3tCRScHlTBS3s0ud5ZqmVSd8t+puJ8T2li+0WMxW/9 /F6BmtHCGYX2B8XMfPuWw8aqQVaE4zjfef8uBQUvzqpe59U= X-Google-Smtp-Source: ADUXVKIeweNRPBBunewx+i7aMJhgyG/BWK7JJD/SSEv6jyZyOvi2W8Ql00uIWjkBs8wm6U/9J/53SbU1TGUAm1n+LgI= X-Received: by 2002:a65:44c8:: with SMTP id g8-v6mr14934458pgs.356.1528726342145; Mon, 11 Jun 2018 07:12:22 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a17:90a:b004:0:0:0:0 with HTTP; Mon, 11 Jun 2018 07:12:21 -0700 (PDT) In-Reply-To: <0d108361-f5fa-fe76-b6ad-66e23bfa88f5@loot.at> References: <0d108361-f5fa-fe76-b6ad-66e23bfa88f5@loot.at> Date: Mon, 11 Jun 2018 16:12:21 +0200 Message-ID: To: Rudolph Gottesheim Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Better types without runtime checking From: rasmus@mindplay.dk (Rasmus Schultz) On Tue, Jun 5, 2018 at 9:22 AM, Rudolph Gottesheim wrote: > ... > Has there ever been a discussion about adding some of those features > syntactically, but ignoring them during runtime? That's what Hack does, and one of the main reasons we dropped Hack in favor of PHP. PHP is a reflective language - if we add e.g. generics or property type-hints, omitting run-time reflection and/or run-time type-checks would be inconsistent with PHP as a language in general. Inconsistencies in a language are surprising and generally "bad" - if type-hints lead to run-time type-checks, it's natural to expect that to work predictably no matter where you type-hint. You shouldn't have to learn where or when type-hints actually work at run-time and where they don't. Similarly, if type-hints are reflected, it's natural to expect all type-hints to exist in the reflection model somewhere, anywhere that type-hinting is possible. You shouldn't have to search the manual to learn that type-hints aren't reflected for properties for some reason, perhaps because it just hasn't been implemented yet. Much of the "good" that we expect to be able to accomplish with generics, for example, won't be possible (or won't make sense) without being consistently reflected and run-time type-checked. For example, in a DI container, I'd expect to be able to do something like this: class Container { public function get(?string $name): T { // ... } // ... } When calling get(), I'd expect a type-check for the the generic return-type T, to protect me against internal errors in the Container implementation - if it returns the wrong type, I want it to fail immediately at that point, rather than potentially exiting the call-stack that made this error traceable, making this extremely difficult to debug. Similarly, if we had property type-hints: class Foo { int $bar; } $foo = new Foo(); $foo->bar = "oops"; Here, I'd expect a type-check when assigning to $bar - omitting that would be extremely bad, as, very likely, by the time something else fails because this object is in an invalid state, we've exited the call stack where the bad value was assigned, making this potentially very difficult to debug. I'd also expect to be able to reflect on the property-types in a DI container, or perhaps in a class that maps form post-data to properties and performs conversions, etc. I'm the author of the generics RFC and one of the property-type RFCs, and both of those RFCs call for both reflection and run-time type-checking, for the sake of keeping the language consistent. Hack made some very regrettable decisions in this area, and ultimately those features were useful at design-time only, for IDE-support - but we have php-doc for that purpose, and in my opinion, adding those features before (or unless) we're willing/able to also make them work consistently with the language, does more harm than good. Making these features appear to be language features, when in fact that they're only implemented in the parser and ignored by the interpreter, would make for an extremely confusing experience.