Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102844 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80865 invoked from network); 16 Jul 2018 11:42:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2018 11:42:05 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.51 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.214.51 mail-it0-f51.google.com Received: from [209.85.214.51] ([209.85.214.51:53726] helo=mail-it0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6B/59-39793-C848C4B5 for ; Mon, 16 Jul 2018 07:42:05 -0400 Received: by mail-it0-f51.google.com with SMTP id 72-v6so4191976itw.3 for ; Mon, 16 Jul 2018 04:42:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=/iPDKNy9tWoLFPTIL85SHZMzRxjvyvbeRFxx/xRrxAY=; b=MClQvSLCcRT6j3N/ObOqT61q0CZLgAbMzu8vEZTqSvb9qSZNxNrKBt4NLLoeOxyEmR f2W6aVmrCDict3cFaPQzAwmM3q6Cf9FUNjuYLpyLTr+X4Q2WflgJ0jfGHaELOv+lh+O/ CJea1sREZhLAYskTfSWmMkVj4AuPKVeERJ/56XbI+wGLkIZ7MItqJ5t9h3Q2Pcp7ARPH 9iET3LG4BMSZOAki3iNFWg/iap9sIic+6srEgZ5CjW1uMAVftuCcvB3ma7WFPnXndEwi qF7YA5lYQBCEi1WkBT19ugjzNM+maLF0Fr+YSZZ9zK3UuddTZ3p8zHyjdcT/Ugcu6oJn 37cA== 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=/iPDKNy9tWoLFPTIL85SHZMzRxjvyvbeRFxx/xRrxAY=; b=JVbjpA3fSaKXN2yLKGCoOT41x5L5KU8piQ4mBhW9+yd6oQIci2kreUWvWGu67UDM4V rNlVROiYnIrmm/9pC7atFQL+o2OcdJOvKaVvkDQmO1IbTxgO2q8/RW6z9hJmhJHT/Q9+ BYM2O3EYvZDf8dikkb9jsYou88fMHXF+rTq4ad6ui5WFYwWZqU8cSiyEFO3G+QWjGpqu 3+ZtwO0NyhJPzNrmzH5k2P+5lwPnZXTZ5C2bG12gBwsTpMPMrkD8ZXk0tDQAyIJZ8RU/ m8L6BaEHjX3m5rKZ3q90Y2FeCQWUfUHd0rgEhNsk2EyTkcEqmuWKR6a0cRLnnv3i8LiA c2WA== X-Gm-Message-State: AOUpUlG0wDxv2YRv5C0DjYAV3keNL5ZFsJ/aYaf0HCFAa4R/uRzHvKvI Uh2OWx1rCsc77rPP5uLl9SwHm5mB0gtRgIUrlGs= X-Google-Smtp-Source: AAOMgpeQ+f4djRpKTaftChX3HLlmnCwRApfp2DBYHOSSp08mMBRFAW9SUqNL+yGX3C0JXuRFgA/Z7wSxmViclhiTKEM= X-Received: by 2002:a24:4048:: with SMTP id n69-v6mr12402359ita.60.1531741321433; Mon, 16 Jul 2018 04:42:01 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:95a8:0:0:0:0:0 with HTTP; Mon, 16 Jul 2018 04:42:00 -0700 (PDT) In-Reply-To: References: Date: Mon, 16 Jul 2018 12:42:00 +0100 Message-ID: To: Arvids Godjuks Cc: mitke013@gmail.com, PHP internals Content-Type: multipart/alternative; boundary="0000000000005a165c05711c51bb" Subject: Re: [PHP-DEV] [RFC] Optional typehint check for parameters From: rowan.collins@gmail.com (Rowan Collins) --0000000000005a165c05711c51bb Content-Type: text/plain; charset="UTF-8" On 16 July 2018 at 12:06, Arvids Godjuks wrote: > Basically, you went wrong when you proposed a switch that controlls > language behavior. To add to that - a switch that probably is not > controllable by code that is running. > While I agree with your general principle here, I would like to raise one point in this proposal's favour, which is that PHP's type hints are effectively assertions - if the value is not of the given type at that point, an error is raised. Assertions are always something you turn off in production builds, with a global switch, to the point of compiling the code as though they don't exist, so it's not unreasonable to have a similar switch to disable run-time type checks. As Nikita points out, this is not true of non-strict scalar hints, so that does raise a complication. I was going to point to Dart as an example where type checks have been implemented this way, but it seems that version 2 has replaced the "checked mode" with stronger static analysis, and run-time checks are automatically inserted only for cases where the safety can't be inferred. This might actually be a more promising optimisation for PHP - perhaps OpCache could mark certain code paths as type-safe (or maybe it already does?) As an exaggerated example, this code only really needs to check the value's type once, not four times: function foo(Bar $bar): Bar { return $bar; } function test(Bar $bar): Bar { return foo($bar); } $something = test($something); Regards, -- Rowan Collins [IMSoP] --0000000000005a165c05711c51bb--