tags:

views:

74

answers:

3

Hello guys :)

I got this code:

codeviewer.org/view/code:b6f

It simply validates a date, but ends the script if a error occurs (exit ()).

Now i gonna put this same code in a single function that returns false on error:

codeviewer.org/view/code:b70

I dont want to use "if/else". I want to return false on error and stop execution of the others things, something like this:

codeviewer.org/view/code:b71

Is that possible ?

Thank you.

+4  A: 

Learn exceptions. Live them. Love them.

Ignacio Vazquez-Abrams
Throwing an exception for a non-valid date from a date-verification function seems a bit much...
jeroen
+3  A: 

you could change

exit ("Error !");

to

return false;

but exceptions would definitely be better as suggested by Ignacio Vazquez-Abrams

Jayrox
+1  A: 

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.

jeroen