Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: skipping a default parameter in a function call

Tags:

php

The below is a php function:

bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )

I would like to call the function, specifying the first and the third parameters, leaving the second default. Can I?

like image 827
shealtiel Avatar asked Dec 15 '10 19:12

shealtiel


2 Answers

No, you cannot. See http://www.php.net/manual/en/functions.arguments.php esp. ex #5 and #6

Specifically:

Note that when using default arguments, any defaults should be on the right side of any non-default arguments; otherwise, things will not work as expected.

like image 185
nico Avatar answered Oct 13 '22 09:10

nico


Make a wrapper function with only the parameters you want to specify.

like image 43
activout.se Avatar answered Oct 13 '22 09:10

activout.se