|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #65772 Implement "default" as a possible function/method argument value in calls
Submitted: 2013-09-27 06:49 UTC Modified: 2018-09-14 15:10 UTC
Avg. Score:4.5 ± 0.5
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: matteo_tassinari_TM at libero dot it Assigned:
Status: Wont fix Package: Variables related
PHP Version: Irrelevant OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: matteo_tassinari_TM at libero dot it
New email:
PHP Version: OS:


 [2013-09-27 06:49 UTC] matteo_tassinari_TM at libero dot it
I think it would be useful if we could use the "default" keyword when passing parameters to a method/function so that the value for the parameter for which "default" is passed automatically takes the defined default value, without need of knowing it.

Test script:
For example, consider this:

function justToTest($a = 10, $b = 0) {
  var_dump($a, $b);

justToTest(default, 5);

Expected result:
The first call should show

int 10
int 0

The second call should show

int 5
int 0

The third call should show

int 10
int 5


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-27 08:03 UTC]
Existing RFC for this exact thing:
 [2013-09-27 18:46 UTC]
-Status: Open +Status: Suspended -Assigned To: +Assigned To: stas
 [2013-09-27 18:46 UTC]
We don't really have a status for "it's in an active RFC", so I guess I'll 
suspend this and assign it to Stas for now, since it's his RFC.
 [2015-01-11 07:35 UTC]
-Status: Suspended +Status: Open
 [2018-09-14 15:04 UTC] abonnementspaul at gmail dot com
Do we have any update on this? I know It's been a while but I would still love to see this implemented.
 [2018-09-14 15:10 UTC]
-Status: Assigned +Status: Wont fix -Assigned To: stas +Assigned To:
 [2018-09-14 15:10 UTC]
The RFC was declined. Reading through the discussion, the main issue was that people favored solving the problem with named parameters instead of default values.

That is, something like
  justToTest(b = 5)
 [2018-09-14 15:19 UTC] spam2 at rhsoft dot net
but now we have nothing, not named params, no way to skip params and no way to state "use whatever default" which makes PHP terrible in that aspect given that visual basic 20 years ago had not such issues 

you can't set the 5th param without the other 4 before which leads to have seek for every caller if you decide to change the defaults and a inline comment if the default is intended or you can't tell later if it was an explicit arbitary value or the default
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 00:03:42 2021 UTC