Re: Why change require_once? A brief explanation of motives
| From: | Sebastian Mendel | Date: | Wed, 18 Jul 2007 11:42:31 +0000 |
| Subject: | Re: Why change require_once? A brief explanation of motives | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-47602@lists.php.net to get a copy of this message | ||
Alexey Borzov schrieb:
> As I already said several times, the most common problem with
> include_path is the following:
>
> require_once '/path/to/pear/dir/DB.php';
> $db = DB::connect('...');
> $db->query('...');
>
> and the person gets an error message stating that class DB_Error doesn't
> have a method named 'query' (duh!). Actual error message from
> include_once is silenced by @ operator.
>
> Well, if that person has some clue (or, more probably) is using a better
> tutorial then he adds error handling:
>
> $db = DB::connect('...');
> if (PEAR::isError($db)) {
> die($db->getMessage());
> }
>
> ...and gets an extremely fucking helpful error message of "Not found".
> The helpful error message *is* present, BTW, but should be output by
> getUserInfo(). But by that time the person in question turns to forums
> for help and I can't honestly say I blame him...
>
> This is *the* most common problem in setting include_path I continue
> seeing up to this day. But I daresay the problem is not in include_path,
> but in overall design of DB class.
yes, this is the point i tried to say with my post also
the user knows how to include the library he needs - but the library needs
to know how to include required libraries
especially if it is a 'sub' library
and if not, it is some other PEAR library which can be easily found the same
way:
include_once dirname(__FILE__) . '/../OtherLib.php';
...
if (! class_exist('OtherLib')) {
throw new MyClass_Exception();
}
...
it is up to the user to catch this error, PEAR are libraries not applications!
of course i see problems there - but i do not see where the RFC solves this
problems! i do not see how the RFC makes it easier for the user! i do not
see any advantage at all! i do not see more flexibility! - sorry
there is also another point that should be addressed but is not:
in allfiles.php should also be a check for the class before including class
definition, cause other PEAR::Libs could also call allfiles.php from other
libs, but the user could have loaded another version of this library already
(another version in another directory) ...
this leads toa nother problem, there should be an unique way to get the
version of a class (Class::VERSION) or something similar, so a lib could
check if the required lib has the right version
--
Sebastian Mendel
www.sebastianmendel.de