|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62787 Named function parameters
Submitted: 2012-08-09 16:01 UTC Modified: 2021-05-28 14:30 UTC
Avg. Score:4.2 ± 1.5
Reproduced:5 of 6 (83.3%)
Same Version:3 (60.0%)
Same OS:2 (40.0%)
From: bouanto at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.4.6RC1 OS: all
Private report: No CVE-ID: None
 [2012-08-09 16:01 UTC] bouanto at gmail dot com
I know this feature request has been made a few times in the last years, but I 
want to reopen this request to add arguments in favor to this feature request.

It would be really nice for developper to be able to call a function like this:
func($param1 => 'value1', $param2 => 'value2');
or a similar way.

The func function would be defined that way:
function func(...$options) {}
or another syntax.
This way, we've got not problem with documentation if we compare to the "array-

The goal of this syntax is to simplify the function call and get shorter code.

Not convinced?

Let's compare two web framework: one in a language that support named function 
parameters and one that doesn't.
Drupal (PHP) and Django (Python).

Drupal uses the "array-way" as you recommend.
Here is the way Drupal allows us to create a database table model:
(go down to the code section)

And look at the "named-parameter-way" in Django in the Test script.

The code is almost five times shorter in python, because of the use of named 
It is the primary reason to include this syntax in PHP:
we can get shorter and cleaner code.

Thanks for considering this feature request once again.
And I hope you will do the right choice now.
I am open to argumentation.

Test script:
Python code almost equivalent to the Drupal code:
from datetime import datetime

from django.db import models

class Node(models.Model):
    vid = models.PositiveIntegerField(default=0, null=False, unique=True)
    changed = models.DateTimeField(, db_index=True, null=False)
    created = models.DateTimeField(, db_index=True, null=False)
    type = models.CharField(default='', max_length=32, null=False)
    title = models.CharField(default='', max_length=255, null=False)
    revision = models.ForeignKey('NodeRevision')
    author = models.ForeignKey('User')


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-28 14:30 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-05-28 14:30 UTC]
Named arguments are available as of PHP 8.0.0.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jun 20 04:01:23 2021 UTC