I have follwing class in file "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";
}
}
?>
I want to print each variable in my other file. Note: Classes are called from spl_autoload_register
When I am trying to print :-
<?php
$obj_super = new super();
echo $obj_super->loadme()->tilt;
echo $obj_super->fireme()->hit;
?>
I am getting error :- Trying to get property of non-object in agent.php
Update: I got it working via this
Hope I am not doing any wrong below :-
<?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'];
?>
Thanks
$this->tilt = ..., etc...public $variableand thanglobal $variableinside function , it's still not working :(stdClass) and assign the local variables to it as properties, then return that object. It's very messy though - what exactly are you trying to do?global. it is pure evil.