Bug #79666 [Opn->Wfx]: Allow to further extend anonymous class
| From: | nikic@php.net | Date: | Tue, 02 Jun 2020 15:52:54 +0000 |
| Subject: | Bug #79666 [Opn->Wfx]: Allow to further extend anonymous class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227279@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79666&edit=1
ID: 79666
Updated by: nikic@php.net
Reported by: michael dot vorisek at email dot cz
-Summary: Allow to fursther extend anonymous class
+Summary: Allow to further extend anonymous class
-Status: Open
+Status: Wont fix
Type: Bug
Package: Scripting Engine problem
PHP Version: 7.4.6
Block user comment: N
Private report: N
New Comment:
This is a "no" from my side. Of course, you or someone else may go through the RFC process
to convince me to the contrary.
Previous Comments:
------------------------------------------------------------------------
[2020-06-02 13:05:09] michael dot vorisek at email dot cz
Parser needs to be fixed also for eval with anonymous string class name (probably everywhere, ie. to
allow to use "class@" as literal and not as "class" kw):
$cl = get_class(new class () extends \stdClass {
public function test() {
echo 'x';
}
});
var_dump($cl);
$v = new $cl();
$v->test();
eval('
$clExtended = get_class(new class () extends '.$cl.' {
public function test() {
echo "y";
}
});
var_dump($clExtended);
$v = new $clExtended();
$v->test();
');
------------------------------------------------------------------------
[2020-06-02 12:58:37] michael dot vorisek at email dot cz
Description:
------------
This is a feature request to further improve AST and allow to extend class defined with variable
and/or anonymous class. See example.
Instancing anonymous class is already possible.
Test script:
---------------
$cl = get_class(new class () extends \stdClass {
public function test() {
echo 'x';
}
});
var_dump($cl);
$v = new $cl();
$v->test();
$clExtended = get_class(new class () extends $cl /* not possible in PHP 7.4 */ {
public function test() {
echo 'y';
}
});
var_dump($clExtended);
$v = new $clExtended();
$v->test();
Expected result:
----------------
string(101) "class@anonymous�/mnt/www..."
x
string(101) "class@anonymous�/mnt/www..."
y
Actual result:
--------------
not possible in PHP 7.4
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79666&edit=1