PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 31, 2022

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

 August 31, 2022     pear, php     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing