|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45197 new $classname(); dont works with namespaces
Submitted: 2008-06-06 23:53 UTC Modified: 2008-06-07 00:28 UTC
From: markus dot ast at hotmail dot de Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.3CVS-2008-06-06 (snap) OS: Vista x64
Private report: No CVE-ID: None
 [2008-06-06 23:53 UTC] markus dot ast at hotmail dot de
first: sry for my english (I am german)

Trying to dynamicly declarate a class in a namespace doesnt works. It doesn't searches in the current namespace, if this class is present. It just searches in the global namespace.

Reproduce code:
namespace Level1::Level2;
class Example
	public function __construct()
		echo 'works!';
$classname = 'Example';
new $classname();

Expected result:
Fatal error: Class 'Example' not found in test.php on line 11


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-06 23:59 UTC]
Dynamic class references require the fully qualified class name (with the namespace in it) because at runtime there is no information about the current namespace.
 [2008-06-07 00:28 UTC] markus dot ast at hotmail dot de
Okay, good to know, thanks!
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Oct 02 19:03:43 2022 UTC