ID: 48209 User updated by: macmade at eosgarden dot com Reported By: macmade at eosgarden dot com Status: Bogus Bug Type: Scripting Engine problem Operating System: MacOS X 10.5.6 (Client) PHP Version: 5.3.0RC2 New Comment:
Sorry for the annoyance... : ) Previous Comments: ------------------------------------------------------------------------ [2009-05-10 09:43:27] johan...@php.net 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 ------------------------------------------------------------------------ [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