ファイル " super.class.php
"に次のクラスがあります
<?php
class super {
public function loadme() {
$tilt = "I am tilted";
$straight = "I am Straight";
$round = "I am round";
$sleep = "I am Sleeping";
}
public function fireme() {
$hit = "I am hit";
$bullet = "I got bullet";
$gun = "Cover me! I am receiving Heavy Firing";
}
}
?>
各変数を他のファイルに出力したい。注:クラスはから呼び出されますspl_autoload_register
印刷しようとしているとき:-
<?php
$obj_super = new super();
echo $obj_super->loadme()->tilt;
echo $obj_super->fireme()->hit;
?>
エラーが発生しています:-Trying to get property of non-object in agent.php
更新:これで機能しました
以下で間違っていないことを願っています:-
<?php
class super {
public $title = array();
public $situation = array();
public function loadme() {
$this->title['tilt'] = "I am tilted";
$this->title['straight'] = "I am Straight";
$this->title['round'] = "I am round";
$this->title['sleep'] = "I am Sleeping";
return $this->title;
}
public function fireme() {
$this->situation['hit'] = "I am hit";
$this->situation['bullet'] = "I got bullet";
$this->situation['gun'] = "Cover me! I am receiving Heavy Firing";
return $this->situation;
}
}
?>
<?php
$obj_super = new super();
$value = $obj_super->loadme();
echo $value['tilt'];
?>
ありがとう