function alwaysFalse(): false
{
return false;
}
This function return is... interesting. function alwaysFalse(): false
{
return false;
}
This function return is... interesting.In my opinion, using Exceptions or nullable types is a better practice in those cases, but I am not against having more options.
Nullable types generally work well, unless you're you have a function that may return nothing, or an error. IE findUser(string $name): ?User wouldn't be able to differentiate between a database error or just not finding a user with that name. Exceptions would work fine here (specifically due to a DB error), but seem a little superfluous for smaller functions.
Personally, I've grown to love the tuple return types of Go/Rust, and I'd love to see first-class support for that within PHP. You can emulate it by returning an array and unpacking it / using list(), but it adds a decent amount of boilerplate and you lose aspects of type covariance in always returning an array.