php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51651 Dynamic class instatiation does not recognize namespaces.
Submitted: 2010-04-23 23:12 UTC Modified: 2010-06-08 13:55 UTC
From: bruno dot p dot reis at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.2 OS: windows vista
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: bruno dot p dot reis at gmail dot com
New email:
PHP Version: OS:

 

 [2010-04-23 23:12 UTC] bruno dot p dot reis at gmail dot com
Description:
------------
When I use a variable value as a class name, the file namespace is not recognized. 

Test script:
---------------
<?php
namespace test;
class Test{}
new Test;
$className = '\test\Test'; 
new $className; // this works
$className = 'Test';
new $className; // this should work either, because this file declares the test namespace, but it does not recognize class Test.

Expected result:
----------------
I expect to see no error. 

Actual result:
--------------
Fatal error: Class 'Test' not found in ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-04-23 23:14 UTC] felipe@php.net
-Package: *General Issues +Package: Scripting Engine problem
 [2010-06-08 13:55 UTC] tony2001@php.net
-Status: Open +Status: Bogus
 [2010-06-08 13:55 UTC] tony2001@php.net
This is a limitation of namespaces in PHP - they are resolved in compile-time.
See http://www.php.net/manual/en/language.namespaces.dynamic.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 05:01:34 2025 UTC