2. 运行时的缺点

3. 逻辑缺点
缺点报告:
缺点 E_ERROR
警告 E_WARNING
把稳 E_NOTICE
开拓阶段:开拓时输出所有的缺点报告,有利于我们进行程序调试
运行阶段:不要让程序输出任何一种缺点报告(不能让用户看到(懂技能, 不懂技能))
将缺点报告写入日志中
一、指定缺点报告 error_reporting = E_LL
二、关闭缺点输出 display_errors = Off
三、开启缺点日志功能 log_errors = On
1. 默认如果不指定缺点日志位置,则默认写WEB做事器的日志中
2. 为error_log选项指定 一个文件名(可写)
3. 写入到操作系统日志中error_log=syslog
//error_reporting(E_ALL);
///ini_set("display_errors", "off");
//ini_set("error_log", "syslog");
//ini_set("MAX_FILEUPLOAD", 200000000);
//echo ini_get("upload_max_filesize");
//error_log("this is a error message!!!!");
非常处理: 意外,是在程序运行过程中发生的猜想这外的事,利用非常改变脚本正常流程
一、PHP5中的一个新的主要特性
if(){
}else{
}
try {
}catch(非常工具){
}
1. 如果try中代码没有问题,则将try中代码实行完后就到catch后实行
2. 如果try中代码有非常发生,则抛出一个非常工具(利用throw),抛出给了catch中的参数, 则在try中代码就不会再连续实行下去
直接跳转到catch中去实行, catch中实行完成, 再连续向下实行
把稳: 提示发生了什么非常,这不是紧张我们要干事,须要在catch中办理这个非常, 如果办理不了,则出去给用户
二、自己定义一个非常类
浸染:便是写一个或多个方法办理当发生这个非常时的处理办法
1. 自己定义非常类,必须是Exception(内置类)的子类,
2. Exception类中的只有布局方法和toString()可以重写, 其它都final
三、处理多个非常
自己定义功能类时如果在方法中抛出非常
class OpenFileException extends Exception {function __construct($message = null, $code = 0){parent::__construct($message, $code);echo "wwwwwwwwwwwwwww<br>";}function open(){touch("tmp.txt");$file=fopen("tmp.txt", "r");return $file;}}class DemoException extends Exception {function pro(){echo "处理demo发生的非常<br>";}}class TestException extends Exception {function pro(){echo "这里处理test发生的非常<br>";}}class HelloException extends Exception {}class MyClass {function openfile(){$file=@fopen("tmp.txt", "r");if(!$file)throw new OpenFileException("文件打开失落败");}function demo($num=0){if($num==1)throw new DemoException("演示出非常");}function test($num=0){if($num==1)throw new TestException("测试出错");}function fun($num=0){if($num==1)throw new HelloException("###########");}}try{echo "11111111111111<br>";$my=new MyClass();$my->openfile();$my->demo(0);$my->test(0);$my->fun(1);echo "22222222222222222<br>";}catch(OpenFileException $e){ //$e =new Exception();echo $e->getMessage()."<br>";$file=$e->open();}catch(DemoException $e){echo $e->getMessage()."<br>";$e->pro();}catch(TestException $e){echo $e->getMessage()."<br>";$e->pro();}catch(Exception $e){echo $e->getMessage()."<br>";}var_dump($file);echo "444444444444444444444<br>";