[php-src] Issue #12895: Incorrect `ReflectionClass::getNamespaceName` for anonymous class

From: Date: Thu, 07 Dec 2023 21:20:33 +0000
Subject: [php-src] Issue #12895: Incorrect `ReflectionClass::getNamespaceName` for anonymous class
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246007@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12895 Author: kubawerlos ### Description The following code: ```php <?php namespace Foo { interface InterfaceFoo {} } namespace Bar { new class implements \Foo\InterfaceFoo {}; } namespace { foreach (get_declared_classes() as $class) { if (!str_contains($class, '@anonymous')) { continue; } echo 'Class: ', $class, PHP_EOL; echo 'Namespace: ', (new ReflectionClass($class))->getNamespaceName(), PHP_EOL; } } ``` Resulted in this output: ``` Class: Foo\InterfaceFoo@anonymousD:\a\php-anonymous-class-namespace\php-anonymous-class-namespace\test.php:8$0 Namespace: Foo\InterfaceFoo@anonymousD:\a\php-anonymous-class-namespace\php-anonymous-class-namespace ``` at Windows and ``` Class: Foo\InterfaceFoo@anonymous/home/runner/work/php-anonymous-class-namespace/php-anonymous-class-namespace/test.php:8$0 Namespace: Foo ``` at Ubuntu But I expected this output instead: ``` Class: Foo\InterfaceFoo@anonymousD:\a\php-anonymous-class-namespace\php-anonymous-class-namespace\test.php:8$0 Namespace: Bar ``` Reproduced at https://github.com/werlos/php-anonymous-class-namespace (see the only [action](https://github.com/werlos/php-anonymous-class-namespace/actions) there). ### PHP Version 8.3.0 ### Operating System _No response_

« previous php.bugs (#246007) next »