错误处理和时间函数 错误处理和时间函数

一、错误处理

a)         错误报告级别

  1. 语法错误: error 会给一个致命错误  终止程序继续执行
  2. 运行时错误: notice warning  运行代码的时候错了 有错误提示,但是他们不会影响程序运行 但是结果不是我们想要的
  3. 逻辑错误:逻辑出现错误  最大的难就 就是不报错  不好排除
  4. notice: 本身不是一个错误  只是一个提示 这个错误可以忽略
  5. warning: 警告只要产生warning错误 程序的执行结果就不是我们想要的,但是这个级别的错误,不会终止程序执行 但是这个错误必须解决掉
  6. error:致命错误  必须排除

b)  调整错误报告级别

E_ERROR   1 致命的运行时错误(阻止代码执行)

E_WARNING 2 运行时警告

E_NOTICE  8  运行时注意

E_ALL           所有的错误 警告的注意信息      

c)  trigger_error 代替die()

trigger_error 可以模拟一个报错信息输出

d)  自定义错误处理

1.屏蔽错误

1.

ini_set()  设置php.ini中的配置项

ini_get()  获取php.ini中的配置项      

2.

error_reporting() 设置错误报告级别

E_ALL^E_NOTICE

E_ALL^E_NOTICE^E_WARNING

3.手动修改错误

a)         ; Possible Values:

b)         ;   Off = Do not display any errors

c)         ;   stderr = Display errors to STDERR (affects only CGI/CLI binaries!)

d)         ;   On or stdout = Display errors to STDOUT

e)         ; Default Value: On

f)          ; Development Value: On

g)         ; Production Value: Off

h)         ; http://php.net/display-errors

i)           display_errors = On 将on 改成off屏蔽错误

或者

; 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_NOTICE

2.自定义错误日志

error_log() 使用指定的文件记录错误报告日志

error_log写入wamp下面的php日志中

; Log errors to specified file. PHP's default behavior is to leave this value

; empty.

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

; Example:

error_log ="c:/wamp/logs/php_error.log"

; Log errors to syslog (Event Log on Windows).

;error_log = syslog

3.以下几种情况可以考虑自定义错误处理

a)         可以记下错误信息 及时发现一些生产环境出现的问题

b)         可以屏蔽错误

c)         可以控制错误的输出

d)         可以作为调试工具

二、时间函数

  1. UNIX 时间戳

自从Unix纪元(格林威治时间1970年1月1日 00:00:00)到现在的秒数

  1. 获取事件戳

time() 函数返回一个当前系统的时间戳

  1.  格式化时间戳

date() 有两个参数 第一个参数是要以什么格式输出  第二个参数是时间戳

                                返回将整数时间戳 按照给定的格式字符串而产生字符串 如果没有给出时间戳则使用本地当前时间戳 换句话来说就是时间戳可选 如果没有就默认当前时间戳

  1. 获取指定时间的时间戳

mktime取的一个日期的unix时间戳

mktime(时,分,秒,月,日,年)

  1. 时区

date_default_timezone_set() 设置时区

参数值:

PRC *

Asia/Shanghai 亚洲/上海

Asia/ChongQing 亚洲/重庆

Asia/Hong_Kong 亚洲/香港

date_default_timezone_get() 获取时区

  1. 用英文文本来描述时间

strtotime() 将任何英文文本的日期和时间描述成时间戳

//unix时间戳的有效期

         //2147483647

        

         echo '<br/>';

         echo date('Y-m-d H:i:s','2147483647');