In a nutshell: how do I access the methods of a class that is instantiated by a method of a different class?
There is a bit of code I am looking at right now that does the following (altering the code is not an option, btw. It isn't mine... I'm just decipher it):
A class has a method that instantiates a different class. It looks something like this:
// this file is named fooClassHere.php class Foo{ public $meh; function bar(){ $something = new Baz; $this->meh = $something->getStuff(); } }
What I am trying to figure out is how to access the methods of this instantiated class Baz. Another page contains something like the following:
include 'bazClassHere.php'; include 'fooClassHere.php'; $a = new Foo; $a->bar();
So shouldn't all of Baz be available now in some manner (and not just getStuff() which I assigned to $this->meh)? The Foo and Baz classes are included, the code instantiates Foo and then calls Foo's method bar() which in turn instantiates the Baz class. Obviously the following will display data returned by Baz's getStuff() method:
var_dump($a->meh);
But I'd like to access all of Baz's available methods without going through the intermediate step of manually assigning them like I did inside Foo's bar method:
$this->meh = $something->getStuff()
Maybe something like (but of course this doesn't work):
$a = new Foo;
$a->bar(); //instantiates Baz as $something $a->something->fromBaz(); //$something is an instance of Baz, yes? No?
I hope this makes sense and I didn't confuse the issue with my notes. Ack! >_<