Returning a Boolean from a Function

If I want to return a BOOLEAN from a Function, which is the proper format…

Choice #1:


	return array("FALSE", $errors[$articleSurveyQuestionID]);

Choice #2:


	return array(FALSE, $errors[$articleSurveyQuestionID]);

Or does it not matter?

Thanks,

Debbie

The latter choice would be the correct one. A boolean is a predefined constant in PHP, so it must not be encased inside any sort of quotation marks. The former choice has a value of “FALSE”, but it’s cast as a string, and so you’ll have to cater for that when wanting to see if the function returns FALSE or not.

You will note that


if ("FALSE") {
    echo "FALSE is true";
}

will output “FALSE is true”, so “FALSE” is not really false; false is, so use the second option.
No need to put it all in caps though (but you can if you want to).

If you really mean that you want to return boolean from a function then you should return either true of false, not an array.
Cheers

Okay, thanks!

Debbie

It was implied that I want to return an array where the first value is a BOOLEAN… :wink:

Debbie

OK, by the way typing boolean in all upper case does not make them more boolean.

The convention in most programming languages is to make TRUE and FALSE upper-case…

Debbie