php错误调试

简介:

Php错误的类别,主要有以下三大类: 

1.       语法错误

程序这种情况通常在执行的时候,会显示错误信息(报错)。这种类型错误会阻止页面php脚本执行其他任务。如:

<?php

Echo 100.

Echo 100;

Echo 101;

?>

执行结果

 

Parse error: syntax error, unexpected ';' in…

 

2.       运行时错误

不会阻止php脚本的运行,但是会阻止该脚本做本身希望做的事情。如下:

<?php

echo  “this is a demo”;

header('Location: http://www.example.com/');

//header()前不能有任何的输出  header() 必须在任何实际输出之前调用

?>

 

执行结果:

this is a demo

Warning: Cannot modify header information - headers already sent by (output started at E:\PhpProject1\test.php:7) in E:\PhpProject1\test.php on line 8

 

 

3.       程序逻辑错误

这种错误不但不会阻止php脚本的执行,也不会显示错误信息。一般用的调试程序手段是异常处理.

<?php

$a=5;

If($a=6){

Echo $a;

}

?>

运行结果为6

 

 

 

报错级别:

错误 ERROR

    页面脚本会停止运行

警告WARNING

    页面脚本不会停止运行

通知NOTICE

页面脚本不会停止运行

 

<?php

/*

*ini_set()

*error_reporting()

*header()

*

*/

 

 

header(“Content-type:text/html;charset=utf-8”);

 

 

echo $a; //Notice: Undefined variable: a

echo "<br/>+++++++++++++++++++++<br/>";

echo "this is a Notice:Undefined variable";

 

 

echo “<p>”;

var_dump();

   echo"<br/>+++++++++++++++++++++<br/>";

echo "This ia a Warning level Warning: Wrong parameter count for var_dump()...";

 

 

echo “<p>”;

ech “This is a demo”;

   echo"<br/>+++++++++++++++++++++<br/>";

echo "This ia a Warning level Warning: Wrong parameter count for var_dump()...";

?>

 

 

 

ini_set()

Sets the value of a configuration option

string ini_set ( string $varname , string $newvalue )

Sets the value of the given configuration option. The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

为给出(指定)的配置选项赋值,在程序执行的过程中,配置选项将保持使用这个新赋给的值。当程序执行完成时,配置选项将恢复系统的默认值

    ini_set(‘display_errors’,1); 开启php.ini中的display_errors

 

error_reporting(E_ALL);

报错程序所有的错误、警告和注意。

 

 

 

error_reporting(E_ALL);

ini_set(‘display_errors’,1);










本文转自 hgditren 51CTO博客,原文链接:http://blog.51cto.com/phpme/667019,如需转载请自行联系原作者
目录
相关文章
|
移动开发 PHP
Visual Studio Code中的PHP提示错误:End of line character is invalid
Visual Studio Code中的PHP提示错误:End of line character is invalid
88 0
|
XML JSON PHP
PHP解析json、xml错误
php内置函数json_decode() 可以解析json字符串 但是有的时候看起来正确的json,解析却一直返回null。 你知道吗,json是可能解析失败的,此时PHP不会产生提示。 我们需要手动通过json_last_error()函数获取
184 0
|
PHP
PHP错误与异常
PHP语言中错误与异常
74 0
PHP错误与异常
|
JavaScript PHP
PHP从零开始--错误处理&&函数
PHP从零开始--错误处理&&函数
PHP从零开始--错误处理&&函数
|
Web App开发 监控 应用服务中间件
PHP 脚本自动监控 Nginx 504错误
#!/usr/bin/php 将该文件命名为 504check.php修改权限 chmod +x 504check.php 然后crontab -e添加一行 * * * * * /xx/504check.php >/dev/null 2>&1 每分钟系统就会自动检测网站是否响应很慢,若如此,则重启。
1010 0
|
PHP 数据库 关系型数据库
PHP 错误与异常处理(一)
PHP 错误与异常处理详解
1878 0
|
NoSQL Linux PHP
使用单进程、strace、gdb调试PHP错误
使用单进程、strace、gdb调试PHP错误PHP一般是在FPM的呵护下运行的,但是某些情况下进程异常崩溃会导致502。下面是解决思想: 1. 单进程运行: php -d display_errors=1 -S 0.
1861 0