Function nesting, this name is a bit confusing and may not be easy to understand. A more common special case of function nesting: recursive functions, that is, functions that nest themselves. I have always thought that there cannot be too many nested functions in PHP. This is because I accidentally used recursion at some point in the past. When the depth of recursion reaches 100, that is, when the number of nested functions reaches 100, the program will report A fatal error. Example as below:
Copy code The code is as follows:
function rt() {
static $i;
echo $i++, '
';
rt();
}
rt ();
die();
The error reported in my win7 + php5.3 environment is as follows: Fatal error: Maximum function nesting level of '100′ reached, aborting!
I always thought it was a limitation of PHP itself, until One day, I switched to the liunx environment and ran it in command line mode, and found that the program entered an infinite loop. There are different results in different environments. Why? Well, we directly searched for the error information in the source code and found that there was no relevant content. We directly debugged the entire execution process and there was no error reported under win. what reason? Switch to win again, search again, and find the error message in xdebug. Starting at line 1242 of the xdebug.c file:
Copy the code The code is as follows:
XG(level)++;
if (XG(level) == XG(max_nesting_level)) {
php_error(E_ERROR , "Maximum function nesting level of '%ld' reached,
aborting!", XG(max_nesting_level));
}
What does this mean? The previous limit on the number of layers of function nesting was added by the xdebug extension. Why is there this limit? In xdebug, xdebug will record each function call, including nested function calls, memory in function calls, time and other values. These values are of great use in analyzing program performance. Without this limit, when there are too many nested levels, the machine will run out of memory. If this is a production environment server, then some services will be unavailable. Of course, this extension will not be added in the production environment. But this extension may be available on a development server shared by multiple people. If the machine is unavailable due to a developer's program error, so that all developers cannot work, I think this may be the reason for adding restrictions.
What should we do if we need to increase the number of layers of this restriction? Change the source code and recompile the xdebug extension? No, there is an item in the xdebug configuration item called xdebug.max_nesting_level. By default, this configuration item is commented in php.ini. Remove the comment and change this value to the value you need, 200? If it’s not enough, then 500, but this value should not be too large. If there is too much recursion, it will have a great impact on the performance of the program. At this time, it would be a better solution to implement recursion in the form of a stack or replace it with a loop. , such as: the implementation of Fibonacci sequence (Fibonacci), it will be faster to use loops to implement it.
Conclusion: There is no limit to the function nesting of PHP itself. If there is a limit, it is also a memory limit. This is because PHP's function nesting is implemented in the form of a stack. For each function, a section of memory is allocated to store the local content of the function.
The above has introduced the analysis of the function nesting layer limit in pptv cracked version 2013 unlimited PHP, including the content of pptv cracked version 2013 unlimited. I hope it will be helpful to friends who are interested in PHP tutorials.