Re: Re: [RFC] Reserving More Types in PHP 7

From: Date: Tue, 28 Apr 2015 12:07:52 +0000
Subject: Re: Re: [RFC] Reserving More Types in PHP 7
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-85988@lists.php.net to get a copy of this message
François Laupretre wrote on 28/04/2015 12:32:
Bare class names are still recognized and priority is given to class names (if a 'String' class is defined, every 'String' or even 'string' type hints will always refer to it).
This part is likely to be rather tricky to implement. How do you know if a 'String' class is defined or not? The Engine would have to do something like this: - check in-scope use statements for resolutions of 'String' to a qualified name - if in namespace scope, try class_exists(__NAMESPACE__ '\String'), invoking autoloader if registered - if not in namespace scope, check class_exists('String'), invoking autoloader if registered - if class found, hint is an object instanceOf check - else, hint is a scalar check All of this (apart from resolving use statements) has to run *every time the hint is processed*, since there is no limit on when a class can become defined. The user has no way of avoiding this penalty, even if they never intend to declare a String class. In contrast, reserving the hint "string" allows the *compiler* to immediately choose a scalar check, and an instanceOf check never needs to run an autoloader, because if the class isn't declared, there can't possibly be an instance of it. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#85988) next »