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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 14:01:29 2024 UTC