Error Control Operators @
来源:互联网 发布:淘宝旺旺登陆失败 编辑:程序博客网 时间:2024/05/17 07:28
Error Control Operators
PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.
If you have set a custom error handler function with set_error_handler() then it will still get called, but this custom error handler can (and should) callerror_reporting() which will return 0 when the call that triggered the error was preceded by an @.
If the track_errors feature is enabled, any error message generated by the expression will be saved in the variable$php_errormsg. This variable will be overwritten on each error, so check early if you want to use it.
<?php
/* Intentional file error */
$my_file = @file ('non_existent_file') or
die ("Failed opening file: error was '$php_errormsg'");
// this works for any expression, not just functions:
$value = @$cache[$key];
// will not issue a notice if the index $key doesn't exist.
?>
Note: The @-operator works only onexpressions. A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it. For instance, you can prepend it to variables, function andinclude calls, constants, and so forth. You cannot prepend it to function or class definitions, or conditional structures such asif and foreach, and so forth.
See also error_reporting() and the manual section forError Handling and Logging functions.
WarningCurrently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.
Error Control Operators
PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.
If you have set a custom error handler function with set_error_handler() then it will still get called, but this custom error handler can (and should) callerror_reporting() which will return 0 when the call that triggered the error was preceded by an @.
If the track_errors feature is enabled, any error message generated by the expression will be saved in the variable$php_errormsg. This variable will be overwritten on each error, so check early if you want to use it.
<?php
/* Intentional file error */
$my_file = @file ('non_existent_file') or
die ("Failed opening file: error was '$php_errormsg'");
// this works for any expression, not just functions:
$value = @$cache[$key];
// will not issue a notice if the index $key doesn't exist.
?>
Note: The @-operator works only onexpressions. A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it. For instance, you can prepend it to variables, function andinclude calls, constants, and so forth. You cannot prepend it to function or class definitions, or conditional structures such asif and foreach, and so forth.
See also error_reporting() and the manual section forError Handling and Logging functions.
Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why.
- Error Control Operators @
- part 2:(Generics,Access Control,Advanced Operators)
- Operators
- Operators
- Operators
- Operators
- RxJava 错误处理操作符(Error Handling Operators)
- RxJava 错误处理操作符(Error Handling Operators)
- Essentials of Error-Control Coding
- Reloading an ActiveX control error
- Error connecting to the Service Control Manager
- XPath Operators
- 14.2 Operators
- 17.9 Operators
- Oracle Operators
- Conversion Operators
- C++ Operators
- Conversion Operators
- 《与君对酒》 徐正坤
- 深入浅出K-Means算法
- 理解矩阵(一)(二)
- 有限制的Burnside , 矩阵幂
- PHP使用empty检查函数返回结果时报Fatal error: Can't use function return value in write context的问题
- Error Control Operators @
- 理解矩阵(三)
- 无线路由桥接(WDS)设置
- 怎样DEBUG 进程IO消耗大的问题
- http://mirror.centos.org/centos/5/addons/x86_64/repodata/repomd.xml错误如何解决
- sfc_os.dll第五号函数替换文件
- blackhat 2012 usa video (验证真货)
- web安全相关问题
- Android开发环境搭建