php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19329 suppressing error messsages with '@' fails
Submitted: 2002-09-10 04:41 UTC Modified: 2002-09-11 06:07 UTC
From: soletan at toxa dot de Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.2.3 OS: Linux 2.4.18
Private report: No CVE-ID: None
 [2002-09-10 04:41 UTC] soletan at toxa dot de
Hi,

is it right to use '@' before function calls to prevent them from producing error messages???

I'm using Apache 2.0.40 with PHP 4.2.3 and Zend Optimizer 2.0 included.

Well, I use it before fopen and get some message, that the file I'm looking for isn't available for reading. After some stress with file_exists I used this to workaround file_exists.

To test that problem I prepared to use 4.3.0-dev snapshot 200209082100 which I used now to test this new failure, again. It reports some error message, too. It is just reformed to say the same with other words. ("failed to create stream: ...")

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-10 09:54 UTC] sniper@php.net
Please provide a short example script..

 [2002-09-10 18:07 UTC] soletan at toxa dot de
Some script example ...

------------------
//	if ( ( @in_array( "DOM", $b["type"] ) ) && file_exists( "../lib/ua-dep/layout-draw-css.php4" ) )
	if ( ( @in_array( "DOM", $b["type"] ) ) && ( $handle = @fopen( "../lib/ua-dep/layout-draw-css.php4", "r" ) ) )
		include( "../lib/ua-dep/layout-draw-css.php4" );
//	else if ( file_exists( "../lib/ua-dep/layout-draw-tables.php4" ) )
	else if ( ( $handle = @fopen( "../lib/ua-dep/layout-draw-tables.php4", "r" ) ) )
		include( "../lib/ua-dep/layout-draw-tables.php4" );
	else
             ... 
------------------

I use this branching to serve the same content in different ways depending on the client's browser. It works great for the second uncommented "if", as soon as I comment out the first one. Without that I have to place some script in given directory with correct name to prevent the error message. Well, but apparently I want the snippet to auto-detect, which module fits best and which is available currently. This feature isn't possible. BTW: The second included script exists of course, the first doesn't ...
 [2002-09-10 19:44 UTC] sniper@php.net
Can you please provide a short, self-contained and ready to copy+paste+run one instead of some snippet of code..?

 [2002-09-11 05:59 UTC] soletan at toxa dot de
Well, here you get one ... but this way I found out, that this "bug" might not be one of your concern. Maybe it's more about error reporting or the scripting engine in general ... I can't decide as I don't know that much about the internals of PHP.

----------------------------
<?php

set_error_handler( "draw_error" );

function draw_error( $numeric, $string ) {
    die( "code: $numeric<BR>message: $string" );
}

if ( $handle = @fopen( "test.php5", "r" ) )
    include( "test.php5" );
if ( $handle )
    fclose( $handle );

?>
----------------------------

This way my error handler gets called even if @-operator supresses error reporting ...
 [2002-09-11 06:07 UTC] mfischer@php.net
Read the manual at http://www.php.net/manual/en/function.set-error-handler.php , this is the expected behaviour.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 16:01:28 2024 UTC