php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #24570 Passing objects as default function parameters
Submitted: 2003-07-09 18:05 UTC Modified: 2004-09-29 22:01 UTC
Votes:3
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: da_bomb at hisplace dot net Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.* OS: *
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: da_bomb at hisplace dot net
New email:
PHP Version: OS:

 

 [2003-07-09 18:05 UTC] da_bomb at hisplace dot net
Description:
------------
Hey,

I've shown a function I'm trying to write that is giving me an error because I can set an object as a default function parameter.

I don't know if this is a bug, or it wasn't intended to be possible but I reckon it would be a good addition. I can't see a specific reason not to have this functionality unless it runs into some issues such as namespaces did.

Thanks :)

Reproduce code:
---------------
public function PadLeft ( Int32 $var1, Char $var2 = new Char ( ' ' ) ) { // line 315
	try {
		$this->Value = str_pad($this->Value, $var1->Value, $var2->ToString(), STR_PAD_LEFT);
		return( true );
	} catch ( xException $ex ) {
		return( $ex->False );
	}
}

Expected result:
----------------
I wasn't expecting to see the error anyway :p

I'd like to have the result I'm looking for returned if possible.

Actual result:
--------------
Parse error: parse error, unexpected T_NEW in D:\www\root\objects\TMP2ct7ths5f1.php on line 315

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-29 09:11 UTC] php at nowhere dot net
This probably shouldnt be supported in the engine. I'm not aware of any languages where this is supported. If you want a default value, then use the existing capability to set it withing the scope of the function.
 [2004-09-29 22:01 UTC] helly@php.net
At the moment the parser/compiler/executor trio doesn't allow this at all. Before we can suppport this we'd need major changes all over the engine becuase the current situation is that we allways have two opcodes for every parameter. Allowing other things as default parameters would break this rule....
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue May 28 02:01:31 2024 UTC