Re: Re: Silencing @
| From: | Ian Eure | Date: | Mon, 31 Oct 2005 23:02:14 +0000 |
| Subject: | Re: Re: Silencing @ | ||
| References: | 1 2 | Groups: | php.pear.qa |
| Request: | Send a blank email to pear-qa+get-3205@lists.php.net to get a copy of this message | ||
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Oct 31, 2005, at 5:24 AM, Helgi Þormar wrote:
On Mon, 31 Oct 2005 13:53:52 +0100, bertrand Gugger wrote:What I typically do is: function factory($driver) {Bonjour, This thema started wirh an IRC discussion about the use of error silencing @. The case was an optional include in some package ("some" = I don't remember which one but a few do/need that) It has an optional feature, just conditioned by the existence of a potential include 'there/option.php'. Naturally, the package will use include or include_once as it's not fatal that 'there/option.php' does not exist: require_once 'there/option.php'; if (class_exist('option') { ... // skipped the '_' <==> '/' translation to be shortMaybe I have to introduce people to file_exists ? People should always use file_exists when they are doing some kind of a driver approach and the driver might not be there (MDB2 and its drivers is one good example, it handles that nicely) Think we should rather focus on that kind of way rather than having some obscure error reporting magic :) Definitely. Silencing errors on include/require is bad (it also suppresses parse errors in the files, leading to troubles during development), and the error fiddling seems excessive.
$file = 'My/Package/' . $driver . '.php;
$class = 'My_Package_Driver';
if (!file_exists($file)) {
return PEAR::raiseError(...);
}
include_once $file;
if (!class_exists($class)) {
return PEAR::raiseError(...);
}
return new $class();
}
Any other suggestions? I don't really like using $driver without veriification. Perhaps filtering it through escapeshellarg()? Not sure this is all CS-worthy, but some best practices would be nice.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Darwin)
iD8DBQFDZqJ2xuUdPD6j2IMRAp2rAKDfXQxK8s3za/0bNvc0gX2BLpqhkwCfa3Sg
brm2LvUIVkVUSe+tNFu3DFk=
=PtJt
-----END PGP SIGNATURE-----