I'd much rather see code that returns an object for success and null for not success. Then, it at least feels like the function is behaving consistently. It's return either an object or the standard way of saying no object null. The same code:

if (prefs) {
// do something
}

works either way, but returning null seems more consistent to me (as the lack of an object) than returning false.

You should either return a default value, or throw an exception . I like throwing exceptions for mandatory things, and delivering default values for optional things. Using null makes debugging a bit more icky, and precludes a key that has null as its value.

This answer differs from others because I've taken your specific use case into account. On any other day, I'd use the null value check.

In this specific case, I probably wouldn't use any of your methods. I'd most likely use an object for preferences with a number of default key/value pairs for any settings that I need. That way, there isn't any special casing needed in any of your code (checks for if(prefs) are not needed).

Consider the following code (how I think I'd go about implementing it anyway):

Like other people said, it's null which must be returned, instead of false. Even with strongly typed languages, you may expect false from a method, which will have a different meaning than null. It's even more important in languages with no type checking. For example, PHP has a similar problem, perfectly illustrated when using readdir method (below, quote and source code from PHP manual):

Please note the fashion in which readdir()'s return value is checked in the examples below. We are explicitly testing whether the return value is identical to (equal to and of the same type as--see Comparison Operators for more information) FALSE since otherwise, any directory entry whose name evaluates to FALSE will stop the loop (e.g. a directory named "0").

/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle))) {
echo "$entry\n";
}
/* This is the WRONG way to loop over the directory. */
while ($entry = readdir($handle)) {
echo "$entry\n";
}