I have lots of functions with optional arguments, which on an omitted value gets its default value from a specified function, currently my code looks something like this:
function get_user($user_id = FALSE) {
// If no ID is passed, get from session
if(!$user_id) {
$user_id = get_id_from_session();
}
// ... do something with the ID
}
It works fine, but it easily gets very clutty when having more then one optional argument. Instead, I'd prefer to do something like the following:
function get_user($user_id = get_id_from_session()) {
// ... do something with the ID
}
I'm sure that you can see how that is more convenient. Is there any way to accomplish this, or do anyone have suggestions on another cleaner approach to do this?