Re: Re: Typed properties patch

From: Date: Thu, 14 Apr 2016 08:11:37 +0000
Subject: Re: Re: Typed properties patch
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-92279@lists.php.net to get a copy of this message
On 04/13/2016 10:31 PM, Stanislav Malyshev wrote:
Hi!
Because if you unset() a property it's type is not guaranteed anymore.
Can't we fix it? I mean, when we unset property on an object, we're still keeping the definition in the class, right? Can't we use it? I didn't understand.
Of course we keep a class definition, where the type of property "$a" - IS_LONG, but the actual value of "$a" may become IS_UNDEF.
<?php class Foo () { int $a = 0; } $a = new Foo(); $b = $a->x + 5; /* we know $a->x is "int" and may use optimized code */ unset($a->x); $b = $a->x + 5; /* $a->x is not "int" any more and we can't use optimized code */
Can't we assume $a->x is still "int" here in a way - I mean, we'd still have to allow for the possibility of null, but if we say that any one could be null it's just one easy check, so it won't hurt performance too much, not? In PHP-7 we check for IS_LONG without type hint.
With type hint and ability to unset(), we will have to check for IS_LONG anyway. So type hinting won't improve reading performance, but writing is going to be slower, because we have to perform type check. So even theoretically this approach couldn't make any improvement. Thanks. Dmitry.


« previous php.internals (#92279) next »