OK so I am trying to figure out if this is possible in php, I haven't had to do it before, and I haven't been able to find anything in the docs, or by googleing (maybe just not searching for it properly).
Let's say I have this bit of code. Pretty simple so far. One class that has a function that creates an instance of the 2nd class.
What I am trying to figure out if I can do is from the function test2 in SecondClass can I call the printMyValue function in the Instance of Firstclass that instanciated the SecondClass object. I would like to do it without passing the FirstClass directly with $this. And I don't want to use FirstClass::printMyValye() as I lose the value passed in from FirstClass::doSomething()
Thanks,
Let's say I have this bit of code. Pretty simple so far. One class that has a function that creates an instance of the 2nd class.
<?php
$myClass = new FirstClass();
$myClass->doSomething();
class FirstClass
{
protected $myValue = null;
public function printMyValue()
{
print $this->myValue;
}
public function doSomething()
{
$this->myValue="testing";
$secondClass = new SecondClass()
$secondClass->doSomething();
}
}
class SecondClass
{
public function doSomething()
{
// call FirstClass::printMyValue() here somehow....
}
}
?>
What I am trying to figure out if I can do is from the function test2 in SecondClass can I call the printMyValue function in the Instance of Firstclass that instanciated the SecondClass object. I would like to do it without passing the FirstClass directly with $this. And I don't want to use FirstClass::printMyValye() as I lose the value passed in from FirstClass::doSomething()
Thanks,
