php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: markus dot ast at hotmail dot de
New email:
PHP Version: OS:

 

 [2008-06-06 23:53 UTC] markus dot ast at hotmail dot de
Description:
------------
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:
---------------
<?php
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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-06 23:59 UTC] colder@php.net
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-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC