Re: Optionally include a script
| From: | Justin Patrin | Date: | Thu, 03 Nov 2005 05:03:30 +0000 |
| Subject: | Re: Optionally include a script | ||
| References: | 1 2 3 | Groups: | php.pear.qa |
| Request: | Send a blank email to pear-qa+get-3218@lists.php.net to get a copy of this message | ||
On 11/2/05, Greg Beaver <cellog@php.net> wrote:
> Justin Patrin wrote:
> > You mean a driver system, right? Same as for DB/MDB/etc? These should
> > also not use @. Either an include should be done and cause an
> > error/failure if it returns false and the PHP error should be left
> > as-is, or the include_path/file_exists system should be used which
> > would also raise an error. I'm in favor of no checking, just include
> > or require it and let the dev deal with missing file warnings.
>
> This is just confusing. People equate PHP warnings with bugs (and they
> should). If you see "file not found MDB2/mysql.php" followed by
> "require_once failed" this is nowhere near to as clear as:
> "MDB2 error: mysql driver (MDB2/mysql.php) not found - is the MDB2_mysql
> package installed?"
>
> Greg
>
> P.S. This is somewhat unfair to Lukas, so please forgive me :). Let's
> just say I'm pretty sure that I know a bit about PHP and a bit more
> about PEAR. Even so, last week when I saw the exact "file not found"
> PHP warning above, I was extremely confused for a while until I figured
> out what my mistake was. The example error message would have saved me
> a good 15 minutes of searching for the mistake in the wrong place.
>
Well, I suppose you have the same gripe as I do about @, except that @
tends to cause a lot more grief since it outputs nothing.
The reason that I say we should just let the error happen is that it
effectively says the same thing as any error the package may raise
(except for in special cases like the MDB2 driver subpackages). In
most cases a failed require or include is a botched install or an
incorrect include_path. Telling the user this with an error is pretty
much the same as allowing the PHP error to happen except for the cases
where the user doesn't check for an error and they see "method called
on a non-object" which is even less helpful. (I'm of course speaking
of PEAR_Error errors here, not exceptions. If PHP5 threw an exception
instead of barfing all over the screen we wouldn't have a problem
here.)
My rationale is that splitting and searching the include_path is
essentially wasted cycles for something that PHP is already doing and
to give an error which is very rarely going to be seen. If it is seen
often then there's probably something wrong with the calling code that
returning a specialized error isn't likely to fix any faster.
--
Justin Patrin