PHP에서 가능한 다중 인스턴스 객체 문제
-
19-08-2019 - |
문제
객체가 호출 되었더라도 35 행의 page.class.php의 비 객체에서 "멤버 함수 process_data ()로 호출됩니다.
Index.php 추출은 인스턴스화되는 물체를 보여주는 다음과 같습니다.
// require our common files
require("modules/module.php");
require("registry/objects/datetime.class.php");
require("registry/objects/page.class.php");
// load in all the objects
$datetime = new dateandtime;
$page = new page;
$module = new module;
그런 다음 프로세스 클래스로 전달됩니다
require("template.class.php");
$template = new template($php_path . "controllers/themes/adm/" . $page . ".html");
// Place in both commonly used language and page specific language
$template->language($php_path . "controllers/language/en/adm/common.php");
$template->language($php_path . "controllers/language/en/adm/" . $page . ".php");
// Tell the page's module to load in data it needs
$module->process_data("module_" . $page);
// Output the final result
$template->output();
이 시점에서 PHP가 오류를 던지고 있습니다. module.php 파일의 내용은 다음과 같습니다
class module {
public function process_data ($child) {
require($child . ".php");
read_data();
return true;
}
}
인스턴스 선언을 두 번째 붙여 넣은 코드 내에서 옮기려고 시도했지만 "모듈"이 호출 한 클래스가 "템플릿"클래스 중 일부를 사용하기 때문에 더 많은 오류가 발생합니다. 라인.
내가 그녀를 잘못 생각하거나 완전히 빠진 것은 그것이 후자라고 확신하지만 여기서 정말 도움이 필요합니다. 감사
해결책
객체 메소드를 호출하려고 할 때 변수 $ 모듈이 범위에없는 것처럼 보입니다. $ module-> process_data ( "module_". $ page) 전에 var_dump ($ module)를 시도해 보시면됩니다. 이 기능의 결과는 무엇입니까? 빠른 솔루션은 Global Global을 선언 할 수 있지만 Globals는 어쨌든 좋은 생각은 아닙니다 (그러나 작동하는지 확인할 수 있습니다).
제휴하지 않습니다 StackOverflow