#48209 [Opn->Bgs]: Namespaces and get_class()
| From: | johannes@php.net | Date: | Sun, 10 May 2009 09:43:29 +0000 |
| Subject: | #48209 [Opn->Bgs]: Namespaces and get_class() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-137095@lists.php.net to get a copy of this message | ||
ID: 48209
Updated by: johannes@php.net
Reported By: macmade at eosgarden dot com
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: MacOS X 10.5.6 (Client)
PHP Version: 5.3.0RC2
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
using string variables as classname will always look from the global NS
Previous Comments:
------------------------------------------------------------------------
[2009-05-09 14:17:35] macmade at eosgarden dot com
Description:
------------
When using the get_class() function on an object whose class is defined
in a different namespace as the actual, the return value does not
contain a leading backslah (which is normal). But then why are we able
to dynamically create an instance, based on the result of get_class(),
without adding a leading backslash?
I don't know if this is a bug, a feature, a wanted or un-wanted
behavior, but I think this is weird.
Reproduce code:
---------------
<?php
namespace Foo;
class Test
{}
namespace Bar;
# Calling 'new Foo\Test()' will obvisously fail, as it won't be found
in the current NS
$TEST = new \Foo\Test();
$CLASSNAME = get_class( $TEST );
# Will display 'Foo\Test' - No leading backslash
print $CLASSNAME . '<br />';
# This will work... Why???
print_r( new $CLASSNAME() );
Expected result:
----------------
Foo\Test
Fatal error: Class 'Bar\Foo\Test' not found ... on line 19
Actual result:
--------------
Foo\Test
Foo\Test Object ( )
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=48209&edit=1