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'];
?>
谢谢