<?php
namespace Vendor\Package;
$test1 = new Foo\Bar(); // works as usual
$test2 = 'Foo\Bar';
$test2 = new $test2(); // does not work
$test3 = 'Vendor\Package\Foo\Bar';
$test3 = new $test3(); // but this works
Run Code Online (Sandbox Code Playgroud)
我正在寻找使用$test2但它不起作用,即使它看起来应该,因为它几乎与$test3工作相同.
这是预期的还是我需要使用一些语法test2来工作?