Re: Re: Silencing @
| From: | Ian Eure | Date: | Tue, 01 Nov 2005 03:53:54 +0000 |
| Subject: | Re: Re: Silencing @ | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.qa |
| Request: | Send a blank email to pear-qa+get-3209@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Alan Knowles wrote:
> Of course the big question you have to ask is: Is this an end user
> error, or a serious program/setup issue.. - in which case good ole
> PHP errors are probably more helpfull than anything you can write.
> (obviously PEAR installer may be a little different, but for most
> PEAR Packages, I suspect the later is the case)
I don't think the cause is relevant, but the effect, which is
uniformly confusing - i.e. "why am I getting a blank page and seeing
no errors."
Greg, your original reply was missing, so I'm replying to it here.
>> Better is:
>>
>> function factory($driver) { $file = 'My/Package/' . $driver .
>> '.php; $class = 'My_Package_Driver'; if (class_exists($class)) {
>> return new $class; } $ip = get_include_path(); foreach
>> (explode(PATH_SEPARATOR, $ip) as $fragment) { if
>> (file_exists($frag . DIRECTORY_SEPARATOR . $file)) { include_once
>> $file; break; } } if (!class_exists($class)) { return
>> PEAR::raiseError(...); } return new $class; }
>>
>> this scans the include_path. Your example will only work if the
>> file is in a subdirectory of the current directory.
I'm not sure this is really a problem in this case - factory() methods
are supposed to load a single kind of object, so if they're stored
uniformly and named consistently, the include_path stuff isn't needed.
And I think that's a good thing.
I've certainly never needed to iterate over the include_path for cases
like that. Have you run into scenarios where this is necessary?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDZubSxuUdPD6j2IMRAsH4AKCFrN+8A1HXUrs/bP8Kw/fRF14rhwCgkyCV
kfe/XoyeK7sDjq3V9MDizBE=
=mUBP
-----END PGP SIGNATURE-----