我理解字符串中复杂(卷曲)语法的用法,但我不理解它在字符串之外的用途.
// $class is a string containg a class name
${$class} =& new $class($settings);
如果有人能帮我理解为什么在这里使用,这和它有什么区别:
$class =& new $class($settings);
谢谢.
解决方法:
最简单的理解方法是通过示例:
class FooBar { }
// This is an ordinary string.
$nameOfClass = "FooBar";
// Make a variable called (in this case) "FooBar", which is the
// value of the variable $nameOfClass.
${$nameOfClass} = new $nameOfClass();
if(isset($FooBar))
echo "A variable called FooBar exists and its class name is " . get_class($FooBar);
else
echo "No variable called FooBar exists.";
使用${$something}或$$.在PHP中称为“变量变量”.