function nesting, the name is a bit tangled, perhaps not very well understood. A more common special case of nested functions: Recursive functions, that is, functions nest themselves. Always thought that in PHP can not have too many function nesting, this is because in the past some time accidentally used recursion, when the depth of recursion reached 100, that is, the function nesting layer reached 100, the program will report a Fatal error. The following example:
Copy CodeThe code is as follows:
function rt () {
static $i;
echo $i + +, '
';
RT ();
}
RT ();
Die ();
In my win7 + php5.3 environment, the error is as follows: Fatal error:maximum function nesting level of ' 100′reached, aborting!
Always think that PHP itself is limited, until one day to switch to the LIUNX environment in the command line mode to run, found that the program is limited to the dead loop. Different circumstances have different results, why? Well, we directly in the source code to find the error message, found that there is no relevant content, directly debug the entire implementation process, there is no error in the win. What's the reason? Switch to win again, find again, found in the Xdebug to see the error message. Start at line 1242 of the Xdebug.c file:
Copy CodeThe 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 that mean? The previous function nesting layer limit is xdebug extension Plus, why this limit? In Xdebug, each function call is recorded in Xdebug, including nested function calls, memory in function calls, and time equivalents, which are used when analyzing program performance. Without this restriction, when the number of nested layers is too many, the machine will run out of memory. If this is a production environment server, then there will be some services are not available, of course, the production environment will not add this extension. However, there may be this extension on a multi-person shared development server, and if the machine is not available because of a developer's program error, so that all developers do not work, I think this may be the reason to add a limit.
What if we need to increase the number of layers in this limit? Change source, recompile xdebug extension? No, there is an item in the Xdebug configuration item called Xdebug.max_nesting_level, by default, in PHP.ini, this configuration item is commented, minus the comment, this value is the value you need, 200? Not enough, that 500, but this value is not too large, if recursion too much, on the performance of the program has a great impact, at this time, the form of a stack to implement recursion or replace recursion with the loop is a better solution, such as: Fibonacci sequence (Fibonacci) implementation, with the loop to achieve faster.
Conclusion: The function nesting of PHP itself is unlimited, if there is a limitation, it is also the limit of memory. This is because the function nesting of PHP is implemented in the form of a stack. For each function, a section of memory is allocated to store the contents of the function parts.
http://www.bkjia.com/PHPjc/323528.html www.bkjia.com true http://www.bkjia.com/PHPjc/323528.html techarticle function Nesting, the name is a bit tangled, perhaps not very well understood. A more common special case of nested functions: Recursive functions, that is, functions nest themselves. Always thought that in PHP can not have ...