In a PHP framework which provides hookpoints that are implemented using eval() I am trying to interrupt or continue a loop from within an eval() call. This is what I am trying
The framework loops like
...
for( $i = 0; $i < 10; $i++ ) {
// framweork code here ...
eval( $plugin_code );
// framweork code here ...
}
...
$plugin_code contains PHP-code - in this sample case
if( $i == 5 ) {
continue;
}
It results in this error
PHP Fatal error: 'continue' not in the 'loop' or 'switch' context
If it is true that eval() only evaluates expressions and can NOT evaluate statements - then how can I implement the continue / break statements inside an eval()?
Leaving aside the mechanics of eval
and continue
for a moment, I think there is a more fundamental point to make: when writing code that "plugs in" to another system, you can only do what that system allows you to do.
If the hook system simply executes the code you give it (whether via eval
, or a callback function, or any other mechanism), you cannot use it to control the flow of loops etc in the main framework code.
If the framework wanted you to do that, it would have to provide a mechanism for your plugin to signal back to the framework what you want it to do - you might register the plugin in a particular way, return a particular value from the callback, set a particular variable, etc.
If you don't want to directly modify the framework, your only option is to request such a feature from the framework's author.