|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-01-11 09:45 UTC] dmitry@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 03:00:01 2025 UTC |
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