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/
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php