ID: 47057 Updated by: dmi...@php.net Reported By: tobias dot john at fondsnet dot de -Status: Assigned +Status: Bogus Bug Type: Scripting Engine problem Operating System: Mac OS X 10.5 PHP Version: 5.3CVS-2009-01-09 (CVS) Assigned To: dmitry New Comment:
Namespaces is a compile time feature. In run-time you should always use full qualified names. You can use a special constant __NAMESPACE__ to do it. $classname2 = __NAMESPACE__ . '\foo\bar\Baz'; Previous Comments: ------------------------------------------------------------------------ [2009-01-09 17:39:14] tobias dot john at fondsnet dot de Description: ------------ When using a variable to instantiate a class, the behavior in namespace resolving is inconsistent to the behavior when using a static class name. Reproduce code: --------------- namespace foo\bar; class Baz { public $value; public function __construct($v) { $this->value = $v; } public function echoValue() { echo 'Value: ' . $this->value, PHP_EOL; } } $classname1 = '\foo\bar\Baz'; $classname2 = 'foo\bar\Baz'; $a = new $classname1('A'); $a->echoValue(); $b = new $classname2('B'); $b->echoValue(); $c = new \foo\bar\Baz('C'); $c->echoValue(); $d = new foo\bar\Baz('D'); $d->echoValue(); Expected result: ---------------- Value: A Fatal error: Class 'foo\bar\foo\bar\Baz' not found in /Users/tj/Documents/workspace/yeti/lib/yeti/NamespaceTest.php on line 20 Actual result: -------------- Value: A Value: B Value: C Fatal error: Class 'foo\bar\foo\bar\Baz' not found in /Users/tj/Documents/workspace/yeti/lib/yeti/NamespaceTest.php on line 24 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47057&edit=1