|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-06-02 12:58 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 16 12:00:01 2025 UTC |
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(); ');