클래스 내에 PHP 변수가있는 파일을 포함 할 수 있습니까? 전체 클래스의 데이터에 액세스 할 수있는 가장 좋은 방법은 무엇입니까?php 클래스에 포함 된 파일
나는 잠시 동안이 문제를 조사해 왔지만 그 중 어떤 사례도 효과가 없었다.
// config.php
$variableSet = array();
$variableSet['setting'] = 'value';
$variableSet['setting2'] = 'value2';
// load config.php ...
include('config.php');
$myClass = new PHPClass($variableSet);
// in class you can make a constructor
function __construct($variables){ // <- as this is autoloading see http://php.net/__construct
$this->vars = $variables;
}
// and you can access them in the class via $this->vars array
당신은 당신이 원하는 무슨에 좀 더 확장 할 수 있습니까? –
그리고 http://stackoverflow.com/search?q=include+file+in+class+php에 질문에 대한 답변이없는 이유를 알려주십시오. – Gordon
이렇게하는 것은 꽤 불가능한 것처럼 보이므로 xml을 사용하여 외부 데이터를로드합니다. – Jerodev