This is not a very complicated algorithm (for 5.5, in 5.6 the described part for class names is the same).
- If necessary, an instance of HashTable is created. It saves imports (used namespace classes).
- When using the as keyword, this name is used as an alias. Else uses the last component of the name of the imported class (for XXX \ YYY \ ZZZ, the name will be ZZZ). Convert it to lowercase.
- Check
self / parent , it cannot be used as a name for an alias. - Check if this name exists in class_table (using the current namespace, if one was declared).
- Add this alias to a special HashTable (see section 1).
Where is this table used?
Only at compile time to resolve class names.
There is another interesting thing about aliases: it has a namespace scope:
<?php namespace nsC { class classC {} } namespace nsA { use nsC\classC as importC; new importC(); } namespace nsB {
source share