interitty / infinite-loop-prevention
A simple infinite loop prevention tool.
Requires
- php: ~8.3
- dg/composer-cleaner: ~2.2
Requires (Dev)
- interitty/code-checker: ~1.0
- interitty/phpunit: ~1.0
README
A simple infinite loop prevention tool that help developers to prevent the error Maximum function nesting level of '256' reached, aborting!
.
Requirements
- PHP >= 8.3
Installation
The best way to install interitty/infinite-loop-prevention is using Composer:
composer require interitty/infinite-loop-prevention
Usage
For cases when an infinite loop can happen, especially when code work with a given callback, it can be handy to call preventive assertion in a non-production environment just to be sure, that code can't fall into an infinite loop.
Because the code is based on debug_backtrace
,
it will be better to disable the mechanism on the production environment by setting the static
InfiniteLoopPrevention::$productionMode
variable.
For better performance in the production environment, it will be better to use the assert
,
because the execution and whole code generating can be disabled by the zend.assertions
in the php.ini
file.
It only needs to call the static method without any parameters just inside the method or function where the given callback is called.
Example: Usage of checkFinite()
function test(): void
{
assert(InfiniteLoopPrevention::checkFinite());
test();
}
test();