Reputation: 23901
I know that the square brackets indicate optional parameters in php documentation. Parameters in PHP documentation, squared brackets?
But does the nesting of brackets have any meaning? Are you supposed to resolve the inner-most bracketed parameters first the way you solve for stuff in the inner parenthesis in math?
In other words, are this
string http_build_url ([ mixed $url [, mixed $parts [, int $flags = HTTP_URL_REPLACE [, array &$new_url ]]]] )
and
string http_build_url ([ mixed $url] [, mixed $parts] [, int $flags = HTTP_URL_REPLACE] [, array &$new_url ] )
equivalent?
Upvotes: 0
Views: 226
Reputation: 158040
No, because the ,
isn't required if only the first param is passed. That's why it is part of the next nested [, param ]
declaration.
Example:
function abc($a); --> [$a] (just a is optional. no , required)
function abc($a, $b); --> [$a [, $b]] (the , is only necessary if you pass $b as well)
Params are nested, because the n+1
th param needs the n
th param to exist. Meaning you can't pass the second param if you didn't passed the first.
This notation is used across all programming languages and other technical documentation to describe optional arguments. I don't know where it is specified, would appreciate some input on that.
Upvotes: 2
Reputation: 32252
No, they are not equivalent.
PHP function parameters are strictly positional and function([$1] [,$2] [,3])
implies that you can simply call the function as function($3);
which is incorrect.
If you wish to invoke a function with only the third optional argument then it must be called as function( , , $3);
This is why PHP.net's function references are listed as function([$1 [,$2 [,$3]]])
Upvotes: 1
Reputation: 7005
Parameters always go in the order they are listed. You don't "Resolve" parameters.
Read the answers in the question you linked to. It means each one is optional.
Upvotes: 1