|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-05-03 18:53 UTC] olav at fwt dot no
Description:
------------
Creating a class from variable when it has been imported with use keyword fails
with class not found error.
This problems persists in 5.3.11, 5.3.12 and 5.4.1
Test script:
---------------
use stdClass as Foo;
$class = "Foo";
new $class;
Expected result:
----------------
No output
Actual result:
--------------
PHP Fatal error: Class 'Foo' not found in /tmp/test.php on line 6
PHP Stack trace:
PHP 1. {main}() /tmp/test.php:0
Fatal error: Class 'Foo' not found in /tmp/test.php on line 6
Call Stack:
0.0003 631856 1. {main}() /tmp/test.php:0
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 14:00:02 2025 UTC |
It seems this problem is not related to the use keyword but imported items in general: file: test2.php ------------------------------------ <?php namespace Foo; class Bar { } file: test.php ------------------------------------ <?php namespace NS2; include 'test1.php'; use Foo\Bar; $class = "Bar"; new $class; Results is the same: --------------------------- Fatal error: Class 'Bar' not found in /tmp/test.php on line 9 Call Stack: 0.0003 632520 1. {main}() /tmp/test.php:0