-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.4] Use do while instead of goto #15973
Conversation
Goto was used because it keeps the call stack down. Your implementation will crash after too many retrys. |
I'm using the following code to get the stack trace, it seems there is no different between do while and goto. Is there something wrong with the following code? do while: https://ideone.com/MYBV9w |
Here is the reasoning for using goto given in the library that inspired the function: igorw/retry#3 |
Here is the opcodes generated using php70, I remove $sleep parameter and optimize goto version to make comparison easier. do_while.php <?php
function retry($times, callable $callback)
{
do {
try {
return $callback();
} catch (Exception $e) {
}
} while (--$times);
throw $e;
} do_while.php opcodes
goto.php <?php
function retry($times, callable $callback)
{
beginning:
try {
return $callback();
} catch (Exception $e) {
if (! --$times) {
throw $e;
}
goto beginning;
}
} goto.php opcodes
@taylorotwell, it seems that goto version takes additional BOOL_NOT(#14) and JMP(#19) opcodes. |
No description provided.