Bug #79666 [Com]: Allow to fursther extend anonymous class

From: Date: Tue, 02 Jun 2020 13:05:09 +0000
Subject: Bug #79666 [Com]: Allow to fursther extend anonymous class
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227276@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 Comment by: michael dot vorisek at email dot cz Reported by: michael dot vorisek at email dot cz Summary: Allow to fursther extend anonymous class Status: Open Type: Bug Package: Scripting Engine problem PHP Version: 7.4.6 Block user comment: N Private report: N New Comment: 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(); '); Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#227276) next »