Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102191 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18941 invoked from network); 6 Jun 2018 10:00:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jun 2018 10:00:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.46 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.46 mail-wm0-f46.google.com Received: from [74.125.82.46] ([74.125.82.46:53047] helo=mail-wm0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EE/E9-62758-AB0B71B5 for ; Wed, 06 Jun 2018 06:00:27 -0400 Received: by mail-wm0-f46.google.com with SMTP id p126-v6so10390133wmb.2 for ; Wed, 06 Jun 2018 03:00:26 -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=i5olF2R0mE2yjzAe6o/XqjOxLWqlN/WQ2sW8d651lxU=; b=il3JuCowt93WCqrknjhzGUc4+QQ9TPRHj6YmGVk45J+CIaBz8tVQ813PUmof7l8vxN ZaNDjl+YHWq5vfVmiKpoBOLWaGyqKw/B9LCtFfiZ05YmIBlYVVdqBZmvBoo5Pj44jhp/ Ee9GdBjCeOgzEwyIwSszT1KECr1B+u50R7ri4zPdMBpXvOXL+7mzgcpdnu2UkcBINg8r ze6IBrrMebJOK9hORRqJN+o4TX3b2x/RQoF9YP4S5cJK+rx9rFbhQjU5WskSRxpwkYrZ axC6MCBQL63ugj2m7Dh4oojGJORPrtYFPB2eZn9DK7/EhPFyDBuVTd+HfoimCa3WynDz 3Uaw== 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=i5olF2R0mE2yjzAe6o/XqjOxLWqlN/WQ2sW8d651lxU=; b=Z8HnxWyT2FeoQY7LbV8xNFbfxtuVDa9vKnk71BvmW/JPYgMVN3MS1tagrORRUyxkCy zD5XGBBxiR7R8Ul20h5njZyowHMEUC9vCKzaCceX5lDr4seDSCTNoGox7lylMNz7izvS iIOu5boDzqeAVnhXQdjQAm4hEqSFCkF3RWKPp2Lohn+EsPbO5zPi43N1Y9emqfeY8hwi B9PwHymotEDzlcz/apvKqdJMmwH1RyUCcnjkPuQuTdL8u7bQs0mgKAOOkUUVot6K2RHb ibnEGsQWm9h9uT+tgNgMZO44lS8tz+o7RY6hNZp40H0XfrwL0AEoWH6fFNXeFLT8cokn Mz8Q== X-Gm-Message-State: APt69E2+iqmEtJwfcP3whjzZjQTjuiWBTCvq8wjzHNb+V3xGDr1ieJs9 0qS7z6C7LksHizeVBcNH+/f5Ju4l8Z3VFTL6/Qg= X-Google-Smtp-Source: ADUXVKIXPVxsVtuypOT1mEQxiOc9zbxce0wAreZcDriomd4EUfu4HskOqovqGw2ivqCjl11Db+b+OofyMZHMlSDZG04= X-Received: by 2002:a50:ba1d:: with SMTP id g29-v6mr2943887edc.85.1528279223770; Wed, 06 Jun 2018 03:00:23 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:8d55:0:0:0:0:0 with HTTP; Wed, 6 Jun 2018 03:00:23 -0700 (PDT) In-Reply-To: References: <0d108361-f5fa-fe76-b6ad-66e23bfa88f5@loot.at> <3c36b189-108d-bce7-bea0-7a3d6a432607@gmail.com> Date: Wed, 6 Jun 2018 11:00:23 +0100 Message-ID: To: Ryan Jentzsch Cc: Internals Content-Type: multipart/alternative; boundary="0000000000004022c4056df63c8b" Subject: Re: [PHP-DEV] Better types without runtime checking From: rowan.collins@gmail.com (Rowan Collins) --0000000000004022c4056df63c8b Content-Type: text/plain; charset="UTF-8" On 6 June 2018 at 07:14, Ryan Jentzsch wrote: > Why would something like this not work? > > strict class MyClass > { > protected int $foo = 1; > public string $bar = "strict keyword in front of class allows/enforces > strict properties"; > private string $isItReallyThatDifficult = "to implement this?"; > } > The problem is not in defining what code has type annotations, it's what to do with them afterwards. The performance hit comes from the fact that *every* time you run: $foo->bar = $baz; The engine now needs to check whether $foo is a class with type constraints, and what the type constraint of bar is, and whether the type of $baz matches that constraint. The answer will be "no constraint" most of the time, but it doesn't know that until it checks, at run-time, every time. Nor is it just straight-forward assignments that would need to change, there are knock-on effects across the language, such as assignment by reference: strict class MyClass { public int $foo; public string $bar; } $a = new MyClass; $inst =& $a->foo; // If this is allowed... $inst = 'bad'; // ...then this needs to error $s = 'good'; $a->bar =& $s; // And if this is allowed... $s = 42; // ... then this needs to error The previous proposal for typed properties simply raised errors when you tried to use reference assignment with any typed property, which feels like an arbitrary restriction to me. The alternative is to allow *every variable in the language* to carry type constraint information. I mused some more on this here: http://rwec.co.uk/q/php-type-system In short, yes, it really is that difficult. Regards, -- Rowan Collins [IMSoP] --0000000000004022c4056df63c8b--