Edit report at https://bugs.php.net/bug.php?id=61928&edit=1

 ID:                 61928
 Updated by:         maar...@php.net
 Reported by:        olav at fwt dot no
 Summary:            Instanciate object for aliased class
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Class/Object related
 Operating System:   Linux 3.3.4
 PHP Version:        5.3.12
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This isn't a bug, see Example 3 @ 
http://www.php.net/manual/en/language.namespaces.importing.php and the note 
"Importing is performed at compile-time, and so does not affect dynamic class, 
function or constant names."

So your code is referencing Foo in the root namespace, which is the documented 
behavior.


Previous Comments:
------------------------------------------------------------------------
[2012-05-03 19:01:09] olav at fwt dot no

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

------------------------------------------------------------------------
[2012-05-03 18:53:28] 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



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61928&edit=1

Reply via email to