私は4つのクラスを持っています。誰かがprintHi.phpに行くと、別のクラスから「hi」を2回印刷します。しかし: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();
を行わずいることだろうか?
エラーを表示するためにアプリケーションの最初の行に 'error_reporting(0)'を追加すると、エラー報告はデフォルトでiniファイル内にあるように見えます。 – RobertPitt