Req #53386 [Opn->Csd]: Allow use function or class for rvalue of static variable
| From: | nikic@php.net | Date: | Fri, 23 Jul 2021 07:36:43 +0000 |
| Subject: | Req #53386 [Opn->Csd]: Allow use function or class for rvalue of static variable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235272@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53386&edit=1
ID: 53386
Updated by: nikic@php.net
Reported by: lifinsky at yandex dot ru
Summary: Allow use function or class for rvalue of static
variable
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Scripting Engine problem
PHP Version: 5.3.3
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
"static $a = new testA()" is supported as of PHP 8.1 (as part of https://wiki.php.net/rfc/new_in_initializers).
Previous Comments:
------------------------------------------------------------------------
[2010-11-23 14:55:42] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=53386&edit=1