You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we stub a previously undefined global function, a new global function is generated.
And then if we re-stub it again without any return value, it gets redefined and an entry is created in GlobalSpies::$redefined_functions (because of changes in this pr). Previously, the re-stub wouldn't work and there would be no entry in GlobalSpies::$redefined_functions.
But a new problem arises when the re-stub is invoked: \Spies\GlobalSpies::handle_call_for is called and in turn \Spies\GlobalSpies::call_original_global_function gets called (since stubbed without a return value).
Since there is an entry for the invoked function in GlobalSpies::$redefined_functions, the previous definition is restored (which happens to be the generated function) and call_user_func_array is called on that. This invokes \Spies\GlobalSpies::handle_call_for again and this keeps happening in a cycle.
Invocation of the second bar above will create an infinite loop.
Note: this case doesn't generate if the global function exists beforehand or if the re-stub has a return value. In those cases, \Spies\GlobalSpies::call_original_global_function is not called and there is no loop.
The text was updated successfully, but these errors were encountered:
If we stub a previously undefined global function, a new global function is generated.
And then if we re-stub it again without any return value, it gets redefined and an entry is created in
GlobalSpies::$redefined_functions
(because of changes in this pr). Previously, the re-stub wouldn't work and there would be no entry inGlobalSpies::$redefined_functions
.But a new problem arises when the re-stub is invoked:
\Spies\GlobalSpies::handle_call_for
is called and in turn\Spies\GlobalSpies::call_original_global_function
gets called (since stubbed without a return value).Since there is an entry for the invoked function in
GlobalSpies::$redefined_functions
, the previous definition is restored (which happens to be the generated function) andcall_user_func_array
is called on that. This invokes\Spies\GlobalSpies::handle_call_for
again and this keeps happening in a cycle.Previously (before this pr), the re-stub wouldn't work and thus the redefinition would never trigger. Only the first generated function or the original global function (had it existed) would be invoked over and over again. In our case, the first generated function calls
\Spies\GlobalSpies::handle_call_for
like above, but it returns early from\Spies\GlobalSpies::call_original_global_function
due to lack of redefinition and thus loop is not created.Example code:
Invocation of the second
bar
above will create an infinite loop.Note: this case doesn't generate if the global function exists beforehand or if the re-stub has a return value. In those cases,
\Spies\GlobalSpies::call_original_global_function
is not called and there is no loop.The text was updated successfully, but these errors were encountered: