|  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
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.
Block user comment
Status: Assign to:
Bug Type:
From: lifinsky at yandex dot ru
New email:
PHP Version: OS:


 [2010-11-23 14:55 UTC] lifinsky at yandex dot ru
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();

Expected result:

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-24 15:34 UTC]
-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]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2021-07-23 07:36 UTC]
"static $a = new testA()" is supported as of PHP 8.1 (as part of
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Aug 05 18:01:23 2021 UTC