php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #36265 Object as default function argument
Submitted: 2006-02-02 20:03 UTC Modified: 2021-10-11 11:04 UTC
Votes:4
Avg. Score:3.5 ± 0.9
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:3 (75.0%)
From: rael at grad dot icmc dot usp dot br Assigned: cmb (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.1.2 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: rael at grad dot icmc dot usp dot br
New email:
PHP Version: OS:

 

 [2006-02-02 20:03 UTC] rael at grad dot icmc dot usp dot br
Description:
------------
In some cases, it's a very usefull feature use an object as default function argument, what is not possible, generating an error in current versions of PHP.

Reproduce code:
---------------
<?php

	class Foo {}
	
	function bar(Foo $foo = new Foo()){}

?>

Expected result:
----------------
A blank webpage.

Actual result:
--------------
Parse error: parse error, unexpected T_NEW in c:\Inetpub\wwwroot\phobos\testes\index.php on line 5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-30 23:33 UTC] cmb@php.net
-Package: Feature/Change Request +Package: Scripting Engine problem
 [2021-10-11 11:04 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-10-11 11:04 UTC] cmb@php.net
This is supported as of PHP 8.1.0[1].

[1] <https://wiki.php.net/rfc/new_in_initializers>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 20:01:36 2025 UTC