<?php
class Statics {
private static $keyword;
public static function __callStatic($name,$args){
self::$keyword = "google";
}
public static function TellMe(){
echo self::$keyword;
}
}
Statics::TellMe();
这是我尝试使用的简单故障,__construct
但我编写代码的方式Statics::TellMe();
需要编写new
才能__construct
工作。而且我的私有静态变量keyword
不会被写入而不被称为任何关于为什么这不起作用的想法?
private static $pathname;
public function __construct($dir = "")
{
set_include_path(dirname($_SERVER["DOCUMENT_ROOT"]));
if($dir !== "") {
$dir = "/".$dir;
}
self::$pathname = $dir.".htaccess";
if( file_exists(self::$pathname) ) {
self::$htaccess = file_get_contents($dir.".htaccess",true);
self::$htaccess_array = explode("\n",self::$htaccess);
}
}
没有被分配,self::$patname
因为我没有这样做$key = new Key();
,所以如果我只是这样做Key::get()
或类似的事情,我需要一种方法来做到这一点。