What you are looking for is technically impossible.
To return false from the original function, you have to explicitly use the return statement – no going around that.
In your example, you will need to use:
return require_parameters( $first_parameter, $second_parameter );
But the definition of require_parameters will have to use varargs as you never know how many arguments you might require.
And, since PHP does not appear to handle varargs directly, you will need to use func_get_args()
and func_num_args()
to check each received arg if it’s set. Docs can be found here.
Update: as Jad pointed out, the error here is that this function will return regardless of outcome. Unfortunately, there is no way (that I know of) to simplify the following, however we can use short-circuit logic to make the check a lot shorter than using a full-blown if
:
Update: My bad, return won’t work after an or
. We can’t go any simpler than this, I’m afraid.
if (!require_parameters( $first_parameter, $second_parameter )) return false;
10
solved Checking if function parameters are not empty, in a different way using php