4 개의 클래스가 있습니다. 누군가 printHi.php로 가면 다른 클래스에서 두 번 "hi"를 인쇄합니다. 그러나 :PHP에서 클래스의 함수를 호출 할 수 없습니다.
printHi.php
include('main.php');
$main = new Main;
main.php :
class Main {
function __construct() {
include('class2.php');
include('class3.php');
$this->class2 = new class2;
$this->class3 = new class3;
$this->class2->sanity();
}
}
class2.php
class class2 {
public function sanity() {
echo "Hi.";
}
}
class3.php
class class3 {
function __construct() {
$this->class2 = new class2;
$this->class2->sanity();
}
}
출력이 표시되지 않습니까? 또는 오류가 있습니까? 내가 도대체 뭘 잘못하고있는 겁니까? 내 모든 클래스의 정신()를 사용하고 싶었 경우
또한, 나는 어떻게 할 것이라고 모든 클래스에
$this->class2 = new class2;
$this->class2->sanity();
을하지 않고?
class class3 {
__construct() {
$this->class2 = new class2;
$this->class2->sanity();
}
}
는 구문 분석 오류가 포함되어 있기 때문에
응용 프로그램의 첫 번째 줄에 오류를 보려면'error_reporting (0)'을 추가하십시오. 오류보고는 기본적으로 ini 파일 내에서 발생합니다. – RobertPitt