Welcome Guest, Not a member yet? Register   Sign In
stop current function and start next
#1

[eluser]luukskywalker[/eluser]
Hi everybody,

I'm having a lot of trouble with a small piece of code.

My problem is in the following code.

Code:
if (ereg("([0-9]{2})/([0-9]{2})/([0-9]{4})", $date1)) {          
Echo "its correct";            
}else{
$this->_function_b();
}

This piece of code is a part of a larger function and i want to call another function when my date is not valid, and stop this function.
This happens at $this->_function_b.
But my the rest of this functions (after this IF-ELSE) also executes.

But i want to stop this function and execute function b

Does anyone know where my problem is?
#2

[eluser]KeyStroke[/eluser]
You could try this:
Code:
if (ereg("([0-9]{2})/([0-9]{2})/([0-9]{4})", $date1)) {          
Echo "its correct";            
}else{
$this->_function_b();
return; // an empty return - it basically stops the function from executing the rest of the code.
}

May I ask why are you doing this though? it seems strange to me.
#3

[eluser]xwero[/eluser]
you can do it by using
Code:
return $this->_function_b();
#4

[eluser]luukskywalker[/eluser]
[quote author="xwero" date="1208788069"]you can do it by using
Code:
return $this->_function_b();
[/quote]

Great works like a charm!

Thanks for the info!




Theme © iAndrew 2016 - Forum software by © MyBB