Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91869 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54561 invoked from network); 22 Mar 2016 19:43:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Mar 2016 19:43:54 -0000 X-Host-Fingerprint: 90.205.35.47 unknown Received: from [90.205.35.47] ([90.205.35.47:3845] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 90/F4-30596-770A1F65 for ; Tue, 22 Mar 2016 14:43:52 -0500 Message-ID: <90.F4.30596.770A1F65@pb1.pair.com> To: internals@lists.php.net References: <56E9C241.1090905@fleshgrinder.com> <3B.AA.03097.757BDE65@pb1.pair.com> <56EEA379.20503@fleshgrinder.com> Date: Tue, 22 Mar 2016 19:43:47 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0 SeaMonkey/2.40 MIME-Version: 1.0 In-Reply-To: <56EEA379.20503@fleshgrinder.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 90.205.35.47 Subject: Re: [PHP-DEV] [RFC Discussion] Typed Properties From: ajf@ajf.me (Andrea Faulds) Hi again, Fleshgrinder wrote: > On 3/19/2016 9:32 PM, Andrea Faulds wrote: >> Fleshgrinder wrote: >>> I see a big problem with the erroring no matter when as others already >>> pointed out, e.g. together with named constructors (or factory methods >>> if you prefer that name) but also with lazy loading. I think that the >>> null value of properties during and after construction should simply be >>> ignored and left to the implementer. I know that it would be nice to >>> have 100% assurance that the property is always set but it would simply >>> result in rules that are too strict for various use cases. I mean, >>> aren't we trying to solve a problem that never was a problem here? >> >> This is actually a problem for optimising PHP. If the compiler cannot be >> sure a property's value actually matches its declared type, it can't >> optimise operations on that property to remove a type check. >> > > Can we optimize operations or is this theoretical? We can do it, in fact as of a week ago PHP 7.1 (or rather the master branch of php-src) has type-specialised opcodes: https://github.com/php/php-src/pull/1825 I haven't looked at Optimizer's type-inference code, but I don't think it currently applies to properties. It would be great if we could extend it to them using the information typed properties provide us, though. > On 3/19/2016 9:32 PM, Andrea Faulds wrote: >> I also think it would be unintuitive if typed properties had some >> exception where they don't obey the given type. If I ask for an integer, >> then surely I should get an integer? >> > > Of course but there is some *void* time until an object is fully > initialized. We've seen many examples now in this thread. That still complicates things. If you need to convert types, I would suggest using something akin to __wakeup or some method to import data from an array. Then you could handle type conversion yourself before assigining to properties. Thanks. -- Andrea Faulds https://ajf.me/