php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #53386 Allow use function or class for rvalue of static variable
Submitted: 2010-11-23 14:55 UTC Modified: 2021-07-23 07:36 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: lifinsky at yandex dot ru Assigned: nikic (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3.3 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: lifinsky at yandex dot ru
New email:
PHP Version: OS:

 

 [2010-11-23 14:55 UTC] lifinsky at yandex dot ru
Description:
------------
Now language allow only constant for static variable in function (static $a = 0).
Please allow functionality such as in C++

Test script:
---------------
class testA {
	private function __constructor(){}
	public static function getInstance() {
		static $a = new testA();
		return $a;
	}

	public function a() {
		return 5;
	}
}

$a = testA::getInstance();
echo $a->a();
exit;

Expected result:
----------------
5

Actual result:
--------------
fatal error
PHP Parse error:  syntax error, unexpected T_NEW

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-24 15:34 UTC] jani@php.net
-Summary: Allow use funtion or class for rvalue of static variable +Summary: Allow use function or class for rvalue of static variable
 [2021-07-23 07:36 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2021-07-23 07:36 UTC] nikic@php.net
"static $a = new testA()" is supported as of PHP 8.1 (as part of https://wiki.php.net/rfc/new_in_initializers).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC