Silencing @
| From: | bertrand Gugger | Date: | Mon, 31 Oct 2005 12:53:52 +0000 |
| Subject: | Silencing @ | ||
| Groups: | php.pear.qa | ||
| Request: | Send a blank email to pear-qa+get-3200@lists.php.net to get a copy of this message | ||
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 short
Problem here is php will throw a warning if the file is absent, even if it's a possible setting.
The common way you find in pear is then a:
@require_once 'there/option.php';
Very bad, as outlined justin in this irc discussion:
yes, @ will silent anything, even a parse error !
In fact, the goal was to prevent only a WARNING,
I want to ask the CS, in such cases, to forbid @ but impose something like:
$current = error_reporting();
error_reporting($current & ~E_WARNING);
require_once 'there/option.php'; // no more @error_reporting($current); Another example for classes needing sessions but having no way to know if it's allready started: $current = error_reporting(); error_reporting($current & ~E_NOTICE); session_start(); error_reporting($current); That's naturally still not perfect as here, any warnings or notices will be silenced ... But a lesser bad. What do you think ? a+ -- bertrand "toggg" Gugger