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]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to