PHP 5.3 introduces a new feature: Namespace, which brings some trouble with Include / Require statement.
Before Namespace, we use Include / Require like this:
- Set proper include_path
- Each class per file with same file name as 'classname.php'
- Require_once 'filename.php' (simply without absolute path)
- Additionally, use __autoload function, also without absolute path
But namespace breaks the rule.
If you did as old way under namespace system, this may happen:
require_once 'class.php'would not work.
Now in __autoload function, class / interface names are brings as format: namespace\classname (interface name), and if you simply put all include files into one folder, and follow the old naming rule: classname.php, naming collision will happen ( Same class name in different namespace ).
So, new way should be introduced:
- Put your class / interface files into folders according to its namespace, the file tree may like:
- namespace 1
- sub-namespace A
- namespace 2
I think the new feature brings too complex include / require / __autoload function into PHP, hoping the designers of PHP could do something to simplify it.