php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #55078 Can't use anonymous function inside array declaration inside a class
Submitted: 2011-06-29 23:54 UTC Modified: 2012-11-23 09:06 UTC
Votes:4
Avg. Score:4.5 ± 0.5
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:1 (25.0%)
From: charlie at charliesomerville dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 5.3.6 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: charlie at charliesomerville dot com
New email:
PHP Version: OS:

 

 [2011-06-29 23:54 UTC] charlie at charliesomerville dot com
Description:
------------
You can't declare an anonymous function in an array declaration inside a class 
declaration.

Test script:
---------------
<?php

class Foo
{
	static $array = array("hi" => function() {
		phpinfo();
	});
}

Foo::$array["hi"]();

Expected result:
----------------
phpinfo being displayed

Actual result:
--------------
Parse error: syntax error, unexpected T_FUNCTION in /path/to/script.php on line 5

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-01 18:46 UTC] felipe@php.net
-Type: Bug +Type: Feature/Change Request
 [2011-07-01 18:46 UTC] felipe@php.net
This is just more one limitation, not a bug. Changing to feature request.
Thanks.
 [2012-11-23 04:38 UTC] nickmokisasian at gmail dot com
When will this feature be supported?
 [2012-11-23 09:06 UTC] laruence@php.net
-Status: Open +Status: Wont fix
 [2012-11-23 09:06 UTC] laruence@php.net
"(propeties) This declaration may include an initialization, but this 
initialization must be a constant value--that is, it must be able to be 
evaluated at compile time and must not depend on run-time information in order 
to be evaluated."
http://www.php.net/manual/pt_BR/language.oop5.properties.php

lambda is a dynamic expression like :

function lambda() use ($variable) {
}

so, we should not allow lambda in class properties initialization.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 09:01:29 2024 UTC