-1 as a return value
Posted
by
dimadima
on Stack Overflow
See other posts from Stack Overflow
or by dimadima
Published on 2012-06-17T15:36:38Z
Indexed on
2012/06/17
21:16 UTC
Read the original article
Hit count: 230
php
This question is specifically about PHP, but I'm guessing it might be applicable to other languages as well.
I've noticed that between PHP4 and PHP5, the designers of the language shifted away from using -1
as a return value to using constants or other forms of output. This makes sense, as -1
is not particularly evocative, and I'm guessing this practice led to confusion.
That said, I am sometimes inclined to return -1
when I want to quickly add another return option to a function, and -1
often seems like a perfectly valid way to express the outcome I am coding for.
So here are my questions:
Is my observation generally correct, regarding the move away from
-1
as a return value in PHP5 vs PHP4?What are the cons of returning
-1
, beyond for the reason I mentioned above, wherein the-1
return value doesn't contribute positively to code clarity?
© Stack Overflow or respective owner