php.net |  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
Votes:6
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bouanto at gmail dot com
New email:
PHP Version: OS:

 

 [2012-08-09 16:01 UTC] bouanto at gmail dot com
Description:
------------
Hello!
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-
way".

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:
http://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_schema/7
(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 
parameters.
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(default=datetime.now, db_index=True, null=False)
    created = models.DateTimeField(default=datetime.now, 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')


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-28 14:30 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-05-28 14:30 UTC] cmb@php.net
Named arguments are available as of PHP 8.0.0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 07:01:29 2024 UTC