|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-05-10 09:43 UTC] johannes@php.net
[2009-05-10 15:37 UTC] macmade at eosgarden dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 03:00:01 2025 UTC |
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 ( )