why doesn't PEAR use absolute paths? [closed]

倾然丶 夕夏残阳落幕 提交于 2020-01-25 11:47:07

问题


Why does PEAR do this:

require_once 'HTML/QuickForm2/Exception.php'; 

Instead of this?:

require_once dirname(__FILE__) . '/Exception.php';

The only thing I could find on the subject is this:

https://pear.php.net/bugs/bug.php?id=17517

It's supposed to be "completely the opposite direction of PEAR standards and design guidelines". My question is... why?


回答1:


PEAR heavily relies on the include path, which makes it possible to overwrite classes by simply prepending another directory to the include path.

Example:

require_once 'Foo/Bar.php';

would look for Foo/Bar.php in each of the directories specified in include_path. If you want to provide your own patched Foo/Bar.php, you can simply do a

set_include_path(__DIR__ . '/patches/' . PATH_SEPARATOR . get_include_path());

and create a file Foo/Bar.php in the patches/ directory. The library classes you're using would now automatically use your custom Foo_Bar class, without needing any modification.



来源:https://stackoverflow.com/questions/15516575/why-doesnt-pear-use-absolute-paths

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!