php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29863 Not constant default argument
Submitted: 2004-08-27 12:31 UTC Modified: 2004-08-27 13:16 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: viraptor at sol dot wsiz dot rzeszow dot pl Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.0.1 OS: Any
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: viraptor at sol dot wsiz dot rzeszow dot pl
New email:
PHP Version: OS:

 

 [2004-08-27 12:31 UTC] viraptor at sol dot wsiz dot rzeszow dot pl
Description:
------------
When started using php 5 I tried to do something like this:
class A {
  private $var;
  function B($arg = $this->var) { ... }
}
Got 'unexpected T_VARIABLE' or course, but I think it would be a nice option to add in a future releases - default arguments computed when function is called. It could be especially useful when used inside classes.
Probably the same as bug #6566, but if it disappeared after php3, it certainly should be turned on again in php5

Expected result:
----------------
Compute default arguments when calling a function, that can create those itself. It will help if you need something like:
function A ($arg = NULL) {
   if($arg == NULL) $arg=$another_arg;
   .....
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-27 13:16 UTC] derick@php.net
You can only use constants as defaults for parameters to functions, this is not going to be changed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 08 20:01:34 2025 UTC