当前位置: 移动技术网 > IT编程>开发语言>PHP > php错误调试

php错误调试

2019年06月19日  | 移动技术网IT编程  | 我要评论

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: );
//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);
作者“我的php之路”

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网