Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一堂课:
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'
如果这不起作用,可能是因为这些类是在两个不同的命名空间中声明的。