How do I set default value of function parameter as today's date?

I tried:

function funcName($today=date('Y-m-d')) {do something}

Throws me this error:

Parse error: syntax error, unexpected '(', expecting ')'


Recommended Answers

All 2 Replies


function func_name($date = null)
        $date = date('Y-m-d');

    // Your code here

From the manual (below example #4): "The default value must be a constant expression, not (for example) a variable, a class member or a function call."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.