Given the following in PHP:
<?php
class foo {
public $bar;
function __construct() {
"Foo Exists!";
}
function magic_bullet($id) {
switch($id) {
case 1:
echo "There is no spoon! ";
case 2:
echo "Or is there... ";
break;
}
}
}
class bar {
function __construct() {
echo "Bar exists";
}
function target($id) {
echo "I want a magic bullet for this ID!";
}
}
$test = new foo();
$test->bar = new bar();
$test->bar->target(42);
I'm wondering if it's possible for the 'bar' class to call the 'magic bullet' method of the 'foo' class. The 'bar' instance is contained by the 'foo' instance, but is not in a parent/child relationship with it. In actuality, I've got many various "bar" classes that "foo" has in an array, each doing something different to $id before wanting to pass it off to the "magic_bullet" function for an end result, so barring a structure change of the class relations, is it possible to access a method of a 'container' instance?