This article to introduce you to Debug_backtrace, Debug_print_backtrace and anonymous functions of some usage analysis, there is need to understand the students do not enter the reference.
Debug_print_backtrace, the difference is that it prints backtracking information directly.
Debug_print_backtrace () is a very low-key function, and few people notice it.
But when I call another object on one object and then call the other object and one of the functions in the file goes wrong, it laughs.
Debug_print_backtrace () can print out the calling process for a page, from where to where to go to a glance.
But this is a PHP5 proprietary function, fortunately in pear, it has been implemented,
First, debug_backtrace it can be traced back to the function of the call information, can be said to be a debugging tool
code as follows |
copy code |
One (); function one () {one ()}; Function () {three ();} Function Three () {Print_r (Debug_backtrace ());} /* Output: Array ( [0] = = Array ( [file] = d:apmservwwwhtdocstestdebugindex.php [line] + = [ Function] = three [args] = array () ), [1] = = Array ( [file] = D:apmservwwwhtdocstestdebug index.php [line] + 6 [function] = +- [args] = array () ), [2] = = Array ( [File] = > d:apmservwwwhtdocstestdebugindex.php [line] + 3 [function] = one [args] = Array () ) )*/ |
Second, debug_print_backtrace it differs from that it will print the backtracking information directly.
Third, anonymous function
The new anonymous function (Anonymous functions), also called the closure function (closures), has been added since PHP 5.3, and the keyword use is also in the anonymous function.
Let's take a look at an example of an anonymous function, as a parameter to a callback function
The code is as follows |
Copy Code |
echo Preg_replace_callback (' ~-([A-z]) ~ ', function ($match) { return Strtoupper ($match [1]); }, ' Hello-world ' ); Output HelloWorld ?> |
Keywords for connecting closures and external variables: use
Closures can hold some variables and values in the context of the code block. PHP by default, anonymous functions cannot invoke the context variables of the code block, but need to use the Using keyword
The code is as follows |
Copy Code |
function Test () { $num = 2; $array = Array (1,2,3,4,5,6,7,8); Print_r (Array_filter ($array, function ($param) use ($num) { Return $param% intval ($num) ==0; }) );} Test ();
|
http://www.bkjia.com/PHPjc/445616.html www.bkjia.com true http://www.bkjia.com/PHPjc/445616.html techarticle This article to introduce you to Debug_backtrace, Debug_print_backtrace and anonymous functions of some usage analysis, there is need to understand the students do not enter the reference. Debug_print_backtrace, different from ...