Boot
클래스를 만들었습니다. 파일 경로를 변경하는 메서드가 있으므로 사용자가이 클래스를 호출하여 다음과 같은 사용자 지정 경로를 설정할 수 있습니다.변경된 속성에 액세스 할 수 없습니다.
index.php
파일에 너무
class Boot
{
private static $_filePath = 'directory/';
public function __construct()
{
require 'system.php';
}
public function init()
{
new System();
}
public function setFilePath($newDir)
{
$this->_filePath = $newDir;
}
public static function getFilePath()
{
return self::_filePath;
}
}
: 시스템 클래스에서 지금
require 'boot.php';
$b = new Boot();
$b->setFilePath('directories/');
$b->init();
나는 이런 식으로 뭔가를 호출
echo Boot::getFilePath();
이고 directories/
으로 표시해야하지만 다시 기본값 인 directory
이 표시됩니다.
이제는이 문제가 static
필드와 관련되어 있지만 어떻게 변경된 값에 액세스 할 수 있습니까? 감사.
아니요, 저는'System'에'Boot'의 인스턴스가 없습니다. 내'index.php' 파일에서'Boot'의 인스턴스를 보았습니다 만,'boot' 내에 선언 된 클래스'system'의'boot' 내부에있는'$ _filePath'의 경로에 접근해야합니다. 나는 지금 더 명확한 지 모른다. –
'System' 생성자에'$ b'를 인수로 넘깁니다. –
이것이 문제를 해결할 수있는 유일한 해결책입니까? –