Reputation: 1015
IN PHP, Is it possible that I could stop a function from an internal function?, for example
function_1(){
......
function2();
....
}
Can I stop function1 using a sentence in function2 but avoiding stopping the whole script?
Upvotes: 0
Views: 239
Reputation: 2372
You can do this if you capture the return value of your second function.
function my_first_function() {
// some code
if( !my_second_function() ) {
return;
}
}
function my_second_function() {
return false;
}
my_first_function();
Of course you need to modify it to meet you needs but that should get you started.
Upvotes: 4
Reputation: 360862
You can use the RunKit extension, which lets you redefined/rename functions. By default it only allows this to be done on user-defined functions, but there's a php.ini setting to enable it for internal functions as well.
That would let you do something like:
runkit_function_rename('print', 'internal_print');
function print(...) {
echo 'welcome to my own implementation of print';
}
However, messing with internal functions can basically break PHP, so use at your own risk.
Upvotes: 0