php - How to use default parameter value in a nested call? -


i have situation: function a (a class method, it's not important, here...) invokes function b.
function a has 1 parameter (say, $p2), default value.
function b has 1 parameter (say, $q2), default value, too.

if function a called without parameter $p2, function b should called without parameter $q2, too, force using it's default value.
if function a called with parameter $p2, function b should called with parameter $q2.

to clearify example:

function a($p1, $p2 = "default value one") {   if ($p2 === "default value") {     b($p1);   } else {     b($p1, $p2);   } }  function b(q1, q2 = "default value two") {   ... } 

of course it's possible use test, in example above, looks me ugly solution... question is:

is there better (faster, cleaner, smarter) code implement use case?

i think should you're looking for:

just function arguments func_get_args(), call next function call_user_func_array().

function a($p1, $p2 = "default value") {     call_user_func_array("b", func_get_args()); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -