Issue
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?
Solution
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.
Answered By - cweiske Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.