Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102199 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51153 invoked from network); 8 Jun 2018 07:30:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Jun 2018 07:30:17 -0000 Authentication-Results: pb1.pair.com header.from=ryan.jentzsch@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ryan.jentzsch@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.195 as permitted sender) X-PHP-List-Original-Sender: ryan.jentzsch@gmail.com X-Host-Fingerprint: 209.85.223.195 mail-io0-f195.google.com Received: from [209.85.223.195] ([209.85.223.195:43662] helo=mail-io0-f195.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8D/37-62758-F703A1B5 for ; Fri, 08 Jun 2018 03:30:07 -0400 Received: by mail-io0-f195.google.com with SMTP id t6-v6so14813270iob.10 for ; Fri, 08 Jun 2018 00:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aSzI/eKykr50iZMVb+sjJCrprapcPkWiF5jsiPGx4mo=; b=BFhAdJrivt0vt3Xrj+sEh0Ej0HnAsqRQg0F7cxUzddto8/2KoS0D69AhDcDi3MSzTO yOeLxekv07ixfP9W5NtABTeInhZJHPT9SQksZnJE1c59GOvTgDPrAOp4aj9y2anCOwyK BShjLAtldN+QCp9kk6mJ5mQ1pH9Ljr8x8nfNThH7wNYNY80rfpkmCeCoNWF3aMn1uNef f8T59x4o+CmlTVXbUIyNmz5C5gXJimxYEXbJXTl95fX7dXcKqdo2B3lf889KSrhsuNgq 2hvge7Fxu4GgSjshkXGm/PL7SYm7wWxwcQOReKsWT5BmTdCCWwE9XvzfV5bedv7hYyl4 ZZew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aSzI/eKykr50iZMVb+sjJCrprapcPkWiF5jsiPGx4mo=; b=WAsrs63cmvu+MRvqU8R7K910ikNVE7CUOQUIW7+3PrKAzXwfGCart8vjEbNMb3EewV fX0UkPnC9Zcpjre+YNCWuzl/ORAE3LAFy3rjF/Xh253vNZW6A2mOCKH5ew9m6TCnQFLl nb9/ZhMHfiZPfamZ6XqrQJrcVccpDXTkrlt7b5RjeTx/aTo8PtldwGUJdGwswd0pl9Gb AwATYv4AdWr7hAITg+5U4v9TioGEP/UbyLkMnwt0NCU8pQWN9nfRQoZT+dk1YZAI0+/3 aZ/MP6ZuJ6+oAyiPmJhIyc2kTby8Swd0M/slzRWZ0jDYef1ZD7VTSvMn0bphWKm/yYXY dxLA== X-Gm-Message-State: APt69E3IoTO/ulw99syWFHI4tdKRpUCaGfZupaLsScnCx+NnU+Ju9KqI nbPXdR7lpyXqMx9gliDV/GA8O8VZQBbbPC61DE4= X-Google-Smtp-Source: ADUXVKLqIXzoWYTAX0L1Wf94bj79i2lBVTL1CRPxnoUR2U1wLl/jcTtttrBqSs/VWWfe0F26qI3D20ZL4JSB1WDBRos= X-Received: by 2002:a6b:a0ce:: with SMTP id j197-v6mr4599835ioe.290.1528443004582; Fri, 08 Jun 2018 00:30:04 -0700 (PDT) MIME-Version: 1.0 References: <0d108361-f5fa-fe76-b6ad-66e23bfa88f5@loot.at> <3c36b189-108d-bce7-bea0-7a3d6a432607@gmail.com> In-Reply-To: Date: Fri, 8 Jun 2018 01:29:38 -0600 Message-ID: To: Rowan Collins Cc: Internals Content-Type: multipart/alternative; boundary="00000000000059031f056e1c5e17" Subject: Re: [PHP-DEV] Better types without runtime checking From: ryan.jentzsch@gmail.com (Ryan Jentzsch) --00000000000059031f056e1c5e17 Content-Type: text/plain; charset="UTF-8" Thanks Rowan for the detailed explanation. I thought that leveraging `__get` / `__set` internally would have addressed many of the type checking issues that you mentioned. I've used __get/__set in userland to enforce property types and hoped that an internal C based solution would something that is reasonable to code and implement. Also, can anyone in internals respond to this inquiry? https://github.com/php/php-src/pull/1797#issuecomment-394434391 On Wed, Jun 6, 2018 at 4:00 AM Rowan Collins wrote: > 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] > --00000000000059031f056e1c5e17--