我有一个类:
class Site
{
public static $url;
}
我给它赋值:Site::$url="whatever";
我还有另一门课:
class Something
{
public function __Construct()
{
echo Site::$url; // does not seem to have scope?
}
}
如何给Something类提供范围。
它应该像上面写的那样工作:
class Site {
public static $url;
}
class Something {
public function __construct() {
echo Site::$url;
}
}
Site::$url = 'whatever';
new Something(); // prints 'whatever'
如果这不起作用,很可能是因为类是在两个不同的命名空间中声明的。