我试图猜测为什么在我的代码中执行不需要的操作。这是我的代码:
的index.php
include_once("MyClass.php");
new MyClass();
MyClass.php
class MyClass{
private $LOG;
function __construct(){
require_once("Initializer.php");
$initializer = new Initializer();
$this->LOG = $initializer->log;
//Calling the function that performs twice
$this->LOG->log("test");
}
}
Initializer.php
class Initializer{
public $log;
function __construct(){
require_once("Log.php");
$this->log = new Log();
}
}
Log.php
class Log{
function __construct(){
echo "This is not displaying twice";
}
//This function is performing twice
public function log($msg){
$logFile = fopen(TARGET_FILE, "a+");
fwrite($logFile, $msg . "\n");
fclose($logFile);
}
}
我在TARGET_FILE
中作为输出获取:
test
test
每次我执行index.php
。
问题出在哪里?提前谢谢。
答案 0 :(得分:0)
它与PHP无关。我检查了具有此规则的.htaccess
文件:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+) index.php [L]
我删除了RewriteCond %{REQUEST_FILENAME} !-d
,它按预期工作。