php - error_reporting foreach,关于php:显示所有错误和警告

更新2:

我现在已经从.php文件中删除了以下内容:

我在php.in i中设置了如下显示错误:

display_errors = On

php.ini中的错误报告设置如下

error_reporting = E_ALL | E_STRICT

重新启动Apache之后,我仍然没有收到任何错误/警告。

更新1:

我已将php.in i中的错误报告更改为:

error_reporting = E_ALL &

~E_DEPRECATED

error_reporting = E_ALL | E_STRICT

之后我重新启动了Apache,例如

/etc/init.d/apache2 restart

但是页面仍然不会显示任何类型的错误/警告。

原始问题:

以下脚本正在生成警告,因为$err在if语句中。为什么这个警告没有显示在Web浏览器的PHP页面上?我必须查看Apache日志才能看到警告。另外,如果我故意将"insert into"更改为"delete into",它不会在PHP页面上显示错误。为什么错误没有显示在实际的PHP页面上?

error_reporting( E_ALL );

?>

if( $_SERVER['REQUEST_METHOD']=='POST' ) {

$err = array();

if( empty( $_POST['display_name'] ) ) $err[] ="display name field is required";

if( empty( $_POST['email'] ) ) $err[] ="email field is required";

if( empty( $_POST['password'] ) ) $err[] ="password field is required";

if( !$err ) {

try {

$DBH = new PDO("mysql:host=localhost;dbname=database1","user","pass" );

$DBH -> setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

$STH = $DBH -> prepare("delete into table1 (display_name, email, password) values ( :display_name, :email, :password )" );

$STH -> bindParam( ':display_name', $_POST['display_name'], PDO::PARAM_STR, 100 );

$STH -> bindParam( ':email', $_POST['email'], PDO::PARAM_STR, 100 );

$STH -> bindParam( ':password', $_POST['password'], PDO::PARAM_STR, 100 );

$STH -> execute();

$STH = $DBH -> prepare("delete into table2 ( username, status, users_id ) values ( :username, :status, :users_id )" );

$strStatus = 1;

$STH -> bindParam( ':username', $_POST['display_name'], PDO::PARAM_STR, 100 );

$STH -> bindParam( ':status', $strStatus, PDO::PARAM_INT, 1 );

$STH -> bindParam( ':users_id', $_POST['referer'], PDO::PARAM_INT, 1 );

$STH -> execute();

$DBH = null;

} catch( PDOException $e ) {

echo $e -> getMessage();

}

header("Location:".$_SERVER['PHP_SELF'] );

exit;

} else {

foreach( $_POST as $key => $val ) {

$form[$key] = htmlspecialchars($val);

}

}

} else {

$form['display_name'] = $form['email'] = $form['password'] = '';

}

?>

register

referers id:

name:

email:

password:

display_errorsini设置的当前值是多少?

我刚检查过,它被设置为错误报告=e_所有&~e_已弃用

请重新阅读我的问题,我们已经知道您的error_reporting设置,因为它在脚本中。

请参阅原始问题中的更新1。

请重新阅读我的问题。display_errors与error_reporting完全不同。另外,您的脚本会覆盖在ini文件中设置的error_reporting值。

请参阅原始问题中的更新2。

尝试类似codepad.viper-7.com/lem5vx的示例脚本,看看是否显示任何错误。

是的,发出通知。

这个网站可以帮助你所有的php-show-all-errors.com

在alinonescript.com/questions/5438060/查看答案…

如何显示PHP错误的可能副本?

显示错误可能在php.ini或apache配置文件中关闭。

您可以在脚本中打开它:

error_reporting(E_ALL);

ini_set('display_errors', 1);

您应该在PHP错误日志中看到相同的消息。

更改php.ini文件后是否需要重新启动apache?

这个问题已经发布了stackoverflow.com/questions/1053424/…

@oshirowanen ini_set()实际上并没有更改php.ini文件,脚本只是"动作",就像在php.ini中设置的那样……来自手册:Sets the value of the given configuration option. The configuration option will keep this new valueduring the script's execution, andwill be restored at the script's ending.。

我不知道我有多少次得到同样的答案。你帮了我很多。谢谢您!:)

@查尔斯,为什么埃多克斯1〔8〕要把埃多克斯1〔9〕移走?难道不包括所有的东西,包括电子公告吗?

@没有。我的原始答案删除了e_通知信息。查尔斯带我去完成任务,我编辑了答案。

显示解析器错误的唯一方法是编辑php.ini文件。ini-set将不工作。

我总是在生产中进行开发,所以除了禁用显示错误之外,打开所有的e_是个好主意,它仍然会将它们记录在错误日志中,对吗?

@当然了,尼克是对的。E_ALL包括E_NOTICE。

对于有疑问的人,不需要重新启动Apache

直接从php.ini文件:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Error handling and logging ;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; This directive informs PHP of which errors, warnings and notices you would like

; it to take action for. The recommended way of setting values for this

; directive is through the use of the error level constants and bitwise

; operators. The error level constants are below here for convenience as well as

; some common settings and their meanings.

; By default, PHP is set to take action on all errors, notices and warnings EXCEPT

; those related to E_NOTICE and E_STRICT, which together cover best practices and

; recommended coding standards in PHP. For performance reasons, this is the

; recommend error reporting setting. Your production server shouldn't be wasting

; resources complaining about best practices and coding standards. That's what

; development servers and development settings are for.

; Note: The php.ini-development file has this setting as E_ALL. This

; means it pretty much reports everything which is exactly what you want during

; development and early testing.

;

; Error Level Constants:

; E_ALL             - All errors and warnings (includes E_STRICT as of PHP 5.4.0)

; E_ERROR           - fatal run-time errors

; E_RECOVERABLE_ERROR  - almost fatal run-time errors

; E_WARNING         - run-time warnings (non-fatal errors)

; E_PARSE           - compile-time parse errors

; E_NOTICE          - run-time notices (these are warnings which often result

;                     from a bug in your code, but it's possible that it was

;                     intentional (e.g., using an uninitialized variable and

;                     relying on the fact it is automatically initialized to an

;                     empty string)

; E_STRICT          - run-time notices, enable to have PHP suggest changes

;                     to your code which will ensure the best interoperability

;                     and forward compatibility of your code

; E_CORE_ERROR      - fatal errors that occur during PHP's initial startup

; E_CORE_WARNING    - warnings (non-fatal errors) that occur during PHP's

;                     initial startup

; E_COMPILE_ERROR   - fatal compile-time errors

; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)

; E_USER_ERROR      - user-generated error message

; E_USER_WARNING    - user-generated warning message

; E_USER_NOTICE     - user-generated notice message

; E_DEPRECATED      - warn about code that will not work in future versions

;                     of PHP

; E_USER_DEPRECATED - user-generated deprecation warnings

;

; Common Values:

;   E_ALL (Show all errors, warnings and notices including coding standards.)

;   E_ALL & ~E_NOTICE  (Show all errors, except for notices)

;   E_ALL & ~E_NOTICE & ~E_STRICT  (Show all errors, except for notices and coding standards warnings.)

;   E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR  (Show only errors)

; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

; Development Value: E_ALL

; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT

; http://php.net/error-reporting

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

对于纯开发,我赞成:

error_reporting = E_ALL ^ E_NOTICE ^ E_WARNING

也别忘了把显示错误设为开。

display_errors = On

之后,在Ubuntu上重新启动Apache服务器:

sudo /etc/init.d/apache2 restart

"PHP0.0.0"?HEH:

"为了纯粹的开发,@johnmagnolia,请转到:error_reporting = E_ALL ^ E_NOTICE ^ E_WARNING",^符号是否连接了这三个选项?如果是这样,那么E_ALL是否已经包括E_NOTICE和E_WARNING?

我可以通过以下代码获得所有错误:

ini_set('display_startup_errors',1);

ini_set('display_errors',1);

error_reporting(-1);

PHP错误可以显示为以下任何一种方法:

ini_set('display_errors', 1);

ini_set('display_startup_errors', 1);

error_reporting(E_ALL);

有关详细信息:

http://www.howtofindit.in/displaying-php-errors/

php文件中的display_errors = on;有syntax error。

在php.ini上设置这些

;display_startup_errors = On

display_startup_errors=off

display_errors =on

html_errors= on

从PHP页面使用适当的过滤器进行错误报告。

可根据需要制作文件归档机。

E_ALL

E_ALL | E_STRICT

您可以在这里看到详细的描述。

// Report simple running errors

error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized

// variables or catch variable name misspellings ...)

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// Report all errors except E_NOTICE

error_reporting(E_ALL & ~E_NOTICE);

// Report all PHP errors (see changelog)

error_reporting(E_ALL);

// Report all PHP errors

error_reporting(-1);

// Same as error_reporting(E_ALL);

ini_set('error_reporting', E_ALL);

Changelog

5.4.0 E_STRICT became part of E_ALL

5.3.0 E_DEPRECATED and E_USER_DEPRECATED introduced.

5.2.0 E_RECOVERABLE_ERROR introduced.

5.0.0 E_STRICT introduced (not part of E_ALL).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值