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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 20:01:36 2025 UTC