Inside the function declaration all values are assigned to variables, so using variable syntax on the outside seems to make sense too.
$api->getFriends($screen_name = 'phpdrama', $include_user_entities = true);
Pro:
- Consistent with function declaration
Con:
- This will resolve in current versions of PHP, meaning potential BC issues.
Inside the function declaration all values are assigned to variables, so using variable syntax on the outside seems to make sense too.
$api->getFriends($screen_name => 'phpdrama', $include_user_entities => true);
Pro:
- Use of
$
in variables to keep things consistent. - Does not compile in current syntax, so no BC issues.
Con:
- This potentially looks like the named parameter should be dynamically referenced with the value of the variable.
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) ...
Avoid using $
when referencing the function.
$api->getFriends(screen_name => 'phpdrama', include_user_entities => true);
Pro:
- Does not compile in current syntax, so no BC issues.
- Thick arrow is consistent with array usage, which is similar to what this is.
Con:
- This potentially looks like the named parameter should be dynamically referenced with the value of a constant.
- The parser will not allow keywords here, so
class='foo'
would throw an error.
Another approach at avoiding the $
symbol.
$api->getFriends(screen_name='phpdrama', include_user_entities=true);
Pro:
- Does not compile in current syntax, so no BC issues.
=
is consistent with the assignment of default values in the function signature.
Con:
- Looks like it is trying to define a constant perhaps(?)
- The parser will not allow keywords here, so
class='foo'
would throw an error.
PDO style named params.
$api->getFriends(:screen_name => 'phpdrama', :include_user_entities => true);
Pro:
- Does not compile in current syntax, so no BC issues.
- Similar to the PDO named parameter solution so not totally alien.
- Uses the same syntax as Ruby.
Con:
- Adds a new symbol
:
which is currently not used.
$api->getFriends(screen_name: 'phpdrama', include_user_entities: true);
Pro:
- Does not compile in current syntax, so no BC issues.
- Does not look like assignment to variable or definition of constant.
Con:
- Parser issues with keywords?
$api->getFriends('screen_name' => 'phpdrama', 'include_user_entities' => true);
Pro:
- Does not compile in current syntax, so no BC issues.
- Unambiguous to the parser.
- Looks like an array.
Con:
- Looks like an array.
At some points is noted that The parser will not allow keywords here, so class='foo' would throw an error. This would be actually become a non-issue if php/php-src#438 gets merged.