I have this code that simply validates a date, but ends the script if a error occurs (exit ()
).
Now i want to put this same code in a single function that returns false
on error.
I dont want to use "if/else". I want to return false
on error and stop execution of the others things.
Is that possible?
you could change
exit ("Error !");
to
return false;
but exceptions would definitely be better as suggested by Ignacio Vazquez-Abrams
Learn exceptions. Live them. Love them.
I see you already have your answer, but as a side note, are you aware that there is a php function that replaces a big part of your function: checkdate()
No need for regex's, if statements, etc.