Req #62787 [Opn]: Named function parameters

From: Date: Wed, 14 Feb 2018 18:44:47 +0000
Subject: Req #62787 [Opn]: Named function parameters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213960@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62787&edit=1 ID: 62787 Updated by: cmb@php.net Reported by: bouanto at gmail dot com Summary: Named function parameters Status: Open Type: Feature/Change Request Package: Unknown/Other Function Operating System: all PHP Version: 5.4.6RC1 Block user comment: N Private report: N New Comment: See <https://wiki.php.net/rfc/named_params>. Previous Comments: ------------------------------------------------------------------------ [2012-08-09 16:01:23] 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') ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62787&edit=1

« previous php.bugs (#213960) next »