- URL: https://www.laruence.com/en/2010/10/12/1763.html
- Please include attribution when republishing.
PHP's namespace implementation is really quite simple.
When you have code like the following:
<?php
namespace Yaf;
class Application {
}
it is in effect the same as declaring a class named AB — of course, you can't declare it directly that way (that is, you can't declare it that way in a PHP script).
And in use, according to the namespace section of the PHP manual, at execution time — whether you use `use`, or write a relative name or an absolute name directly — when it finally looks up the class table, everything has been converted into a final class name like the one above.
For example:
<?php use Yaf as A; $a = new AApplication(); //converted to YafApplication
It has to be said that PHP's namespace solution is the one with the smallest cost and the smallest impact.
For extension developers, the impact is even more minimal. You only need to change the original form "Yaf_Application" to "Yaf\\Application" at the point of INIT_CLASS_ENTRY, and you've implemented your own namespace.
Be First to Comment