问题描述
PEAR 为什么要这样做:
Why does PEAR do this:
require_once 'HTML/QuickForm2/Exception.php';
而不是这个?:
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
它应该是与 PEAR 标准和设计指南完全相反的方向".我的问题是……为什么?
It's supposed to be "completely the opposite direction of PEAR standards and design guidelines". My question is... why?
推荐答案
PEAR 严重依赖于包含路径,这使得通过简单地将另一个目录添加到包含路径来覆盖类成为可能.
PEAR heavily relies on the include path, which makes it possible to overwrite classes by simply prepending another directory to the include path.
示例:
require_once 'Foo/Bar.php';
将在 include_path
中指定的每个目录中查找 Foo/Bar.php
.如果你想提供你自己的补丁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());
并在 patches/
目录中创建一个文件 Foo/Bar.php
.您正在使用的库类现在将自动使用您的自定义 Foo_Bar
类,无需任何修改.
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.
这篇关于为什么 PEAR 不使用绝对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!