RE: [PHP] blocking warning: Warning: fclose()
| From: | Rick Fletcher | Date: | Tue, 30 Mar 2004 19:16:18 +0000 |
| Subject: | RE: [PHP] blocking warning: Warning: fclose() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-181856@lists.php.net to get a copy of this message | ||
> The problem is when the query does not succeed it outputs this:
>
> Warning: fclose(): supplied argument is not a valid stream
> resource in c:\php\www\test-scripts\index.php on line 42
>
> is there any way to "block" just this warning while keeping
> all other error handling as is?
Yes, the error control operator (@).
<?php @fclose( $fp ); ?>
Reference: http://www.php.net/manual/en/language.operators.errorcontrol.php
Though as another poster pointed out, adding some checking would be a better
approach. You could simply test to see whether it is a resource, or even go
so far as to check that it's a file resource.
<?php
if( is_resource( $fp ) && get_resource_type( $fp ) == "file" ) {
fclose( $fp );
}
?>
Cheers,
Rick