1
제 질문을 올바르게 말하면 잘 모르겠습니다. 나는 정의의 목록을 설정하는 일을하는 수업을 가지고있다. 내 기능 중 하나는 몇 가지 디렉토리 경로를 설정하는 것입니다. 나는 새로운 객체를 설정할 때 그 함수로 올바르게 확장하는 방법을 잘 모르겠습니다. 아래를 참조하십시오.확장 기능을 사용하여 속성을 설정하는 방법은 무엇입니까?
class VM_Definitions
{
public $root;
public $ext;
public $tsk;
public $gbl;
public $sys;
public $sql;
public $db;
public function __construct()
{
$this->root = $_SERVER['DOCUMENT_ROOT'];
/*==============================
COMMONLY USED FILE EXTENSIONS
==============================*/
// Extension for include files
$this->ext = '.inc.php';
// Extension for database processing files
$this->dbe = '.db.php';
// Extension for task files
$this->tsk = '.task.php';
// Extension for global report files
$this->gbl = 'global.php';
// Extension for task files
$sys = '.proc.php';
}
public function DB_Directory($root)
{
/*==============================
MAIN DATABASE DIRECTORY PATH
==============================*/
$this->sql = $root.'/db/';
$this->db = $this->sql;
}
}
//THIS WORKS FINE
$def = new VM_Definitions;
//THIS DOES NOT
$ms_Database = new VM_Definitions::DB_Directory($def->root);
공식 문서 http://php.net/manual/en/language.oop5.php – PeeHaa
을 참조하십시오. VM_Definitions :: DB_Directory <-이 선언은 정적 함수를 호출하는 데 사용됩니다. 객체를 초기화합니다. 여기서 수행하는 클래스를 초기화하지 않고는이 함수를 사용할 수 없습니다 : $ def = new VM_Definitions; 따라서 함수에 대한 적절한 호출은 다음과 같아야합니다 : $ def-> DB_Directory ($ def-> root); – Mark
@Mark $ ms_Database는 새로운 개체입니다. 그래서 내가해야한다고 말하는 것입니다 $ ms_Database = new VM_Definitions; $ ms_Database-> DB_Directory ($ def-> root); –