While I've taught myself a great deal, today I have been struggling with an unexpected behaviour of calling parameters in a function.
Here's an example function:
public function example($foo = null, $bar = null) {
if ($foo) {
// Do something
}
if ($bar) {
// Do Something
}
}
Now if I write a call that looks like the following, I was expecting to call $bar (the second parameter) instantly, which is not the case - and it makes sense to me why.
$this->example($bar);
Is there a way to just call the second parameter without using the following?
$this->example(null, $bar);
$this->example(null, $bar);. Otherwise$barwill be assigned as the first parameter.$this->example(null, $b);or$this->example($a, $b);or$this->example($blah);func_get_args()and pass an array to your function, like this Example. (Not the best practice at all though. I'd avoid this personally.)