1、PHP函数库分类十五PHP函数库分类十五5.PHP错误处理 debug_backtrace- Generates a backtracedebug_backtrace(PHP 4 = 4.3.0, PHP 5)debug_backtraceGenerates a backtrace说明arraydebug_backtrace(int$options= DEBUG_BACKTRACE_PROVIDE_OBJECT,int$limit= 0 )debug_backtrace()generates a PHP backtrace.参数optionsAs of 5.3.6, this paramete
2、r is a bitmask for the following options:debug_backtrace()optionsDEBUG_BACKTRACE_PROVIDE_OBJECTWhether or not to populate the object index.DEBUG_BACKTRACE_IGNORE_ARGSWhether or not to omit the args index, and thus all the function/method arguments, to save memory.Before 5.3.6, the only values recogn
3、ized areTRUEorFALSE, which are the same as setting or not setting theDEBUG_BACKTRACE_PROVIDE_OBJECToption respectively.limitAs of 5.4.0, this parameter can be used to limit the number of stack frames returned. By default (limit=0) it returns all stack frames.返回值Returns an array of associativearrays.
4、 The possible returned elements are as follows:Possible returned elements fromdebug_backtrace()名字类型说明functionstringThe current function name. See also_FUNCTION_.lineintegerThe current line number. See also_LINE_.filestringThe current file name. See also_FILE_.classstringThe currentclassname. See als
5、o_CLASS_objectobjectThe currentobject.typestringThe current call type. If a method call, - is returned. If a static method call, : is returned. If a function call, nothing is returned.argsarrayIf inside a function, this lists the functions arguments. If inside an included file, this lists the includ
6、ed file name(s).更新日志版本说明5.4.0Added the optional parameterlimit.5.3.6The parameterprovide_objectchanged tooptionsand additional optionDEBUG_BACKTRACE_IGNORE_ARGSis added.5.2.5Added the optional parameterprovide_object.5.1.1Added the currentobjectas a possible return element.范例Example #1debug_backtrac
7、e()exampleResults similar to the following when executing/tmp/b.php:Hi: friendarray(2) 0=array(4) file = string(10) /tmp/a.php line = int(10) function = string(6) a_test args= array(1) 0 = &string(6) friend 1=array(4) file = string(10) /tmp/b.php line = int(2) args = array(1) 0 = string(10) /tmp/a.p
8、hp function = string(12) include_once debug_print_backtrace- Prints a backtracedebug_print_backtrace(PHP 5)debug_print_backtracePrints a backtrace说明voiddebug_print_backtrace(int$options= 0,int$limit= 0 )debug_print_backtrace()prints a PHP backtrace. It prints the function calls, included/required fi
9、les andeval()ed stuff.参数optionsAs of 5.3.6, this parameter is a bitmask for the following options:debug_print_backtrace()optionsDEBUG_BACKTRACE_IGNORE_ARGSWhether or not to omit the args index, and thus all the function/method arguments, to save memory.limitAs of 5.4.0, this parameter can be used to
10、 limit the number of stack frames printed. By default (limit=0) it prints all stack frames.返回值没有返回值。更新日志版本说明5.4.0Added the optional parameterlimit.5.3.6Added the optional parameteroptions.范例Example #1debug_print_backtrace()example以上例程的输出类似于:#0 c() called at /tmp/include.php:10#1 b() called at /tmp/i
11、nclude.php:6#2 a() called at /tmp/include.php:17#3 include(/tmp/include.php) called at /tmp/test.php:3 error_get_last- Get the last occurred errorerror_get_last(PHP 5 = 5.2.0)error_get_lastGet the last occurred error说明arrayerror_get_last(void)Gets information about the last error that occurred.返回值Re
12、turns an associative array describing the last error with keys type, message, file and line. If the error has been caused by a PHP internal function then the message begins with its name. ReturnsNULLif there hasnt been an error yet.范例Example #1 Anerror_get_last()example以上例程的输出类似于:Array( type = 8 mes
13、sage = Undefined variable: a file = C:WWWindex.php line = 2) error_log- Send an error message somewhereerror_log(PHP 4, PHP 5)error_logSend an error message somewhere说明boolerror_log(string$message,int$message_type= 0,string$destination,string$extra_headers )Sends an error message to the web servers
14、error log or to a file.参数messageThe error message that should be logged.message_typeSays where the error should go. The possible message types are as follows:error_log()log types0messageis sent to PHPs system logger, using the Operating Systems system logging mechanism or a file, depending on what t
15、he error_log configuration directive is set to. This is the default option.1messageis sent by email to the address in thedestinationparameter. This is the only message type where the fourth parameter,extra_headersis used.2No longer an option.3messageis appended to the filedestination. A newline is n
16、ot automatically added to the end of themessagestring.4messageis sent directly to the SAPI logging handler.destinationThe destination. Its meaning depends on themessage_typeparameter as described above.extra_headersThe extra headers. Its used when themessage_typeparameter is set to1. This message ty
17、pe uses the same internal function asmail()does.返回值成功时返回TRUE, 或者在失败时返回FALSE.更新日志版本说明5.2.7The possible value of 4 was added tomessage_type.范例Example #1error_log()examples error_reporting- Sets which PHP errors are reportederror_reporting(PHP 4, PHP 5)error_reportingSets which PHP errors are reported说
18、明interror_reporting(int$level )Theerror_reporting()function sets the error_reporting directive at runtime. PHP has many levels of errors, using this function sets that level for the duration (runtime) of your script. If the optionallevelis not set,error_reporting()will just return the current error
19、reporting level.参数levelThe new error_reporting level. It takes on either a bitmask, or named constants. Using named constants is strongly encouraged to ensure compatibility for future versions. As error levels are added, the range of integers increases, so older integer-based error levels will not a
20、lways behave as expected.The available error level constants and the actual meanings of these error levels are described in the predefined constants.返回值Returns the old error_reporting level or the current level if nolevelparameter is given.更新日志版本说明5.4.0E_STRICTbecame part ofE_ALL.5.3.0E_DEPRECATEDan
21、dE_USER_DEPRECATEDintroduced.5.2.0E_RECOVERABLE_ERRORintroduced.5.0.0E_STRICTintroduced (not part ofE_ALL).范例Example #1error_reporting()examples注释WarningMost ofE_STRICTerrors are evaluated at the compile time thus such errors are not reported in the file where error_reporting is enhanced to includeE
22、_STRICTerrors (and vice versa).TipPassing in the value-1will show every possible error, even when new levels and constants are added in future PHP versions. TheE_ALLconstant also behaves this way as of PHP 5.4. restore_error_handler- Restores the previous error handler functionrestore_error_handler(
23、PHP 4 = 4.0.1, PHP 5)restore_error_handlerRestores the previous error handler function说明boolrestore_error_handler(void)Used after changing the error handler function usingset_error_handler(), to revert to the previous error handler (which could be the built-in or a user defined function).返回值This fun
24、ction always returnsTRUE.范例Example #1restore_error_handler()exampleDecide ifunserialize()caused an error, then restore the original error handler.以上例程会输出:Invalid serialized value.注释Note:Callingrestore_error_handler()from theerror_handlerfunction is ignored. restore_exception_handler- Restores the previously defined exception handler functionrestore_exception_handler(PHP 5)restore_exception_handlerRestores the
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1