Search code examples
phpparametersdefault

PHP meta default parameter


With the code:

function basic($test='David') {
    return "Test='".$test."';";
}

function using($test) {
    return basic($test);
}

echo using();

Suppose I din't create the function basic but I wanna propagate the default parameter [mind the difference between parameter and argument: What's the difference between an argument and a parameter? ]

In English: say basic is encapsulated, I don't know of the default value 'David' but I wanna be able to call using without passing an argument. But the output to be David; if you feel me?

But hey without mentioning David in the using function. I thought null value will do it or as blank as I did in the code sample.

My question is: is there a [default] value that represent the absence of the argument so that the default is in effect for a remote function that you don't know it's default value?

This question is simple but what of a complex function that you can't trace the processing of the argument to derive [~suggest] it's default. How can we have a pronoun default? -If you get me!


Solution

  • function using($test = null) {
        if(!$test)
            return $this->basic();
        return $this->basic($test);
    }