PHP Access property of a class from within a class instantiated in the original class.
Posted
by Iain
on Stack Overflow
See other posts from Stack Overflow
or by Iain
Published on 2010-03-19T17:27:06Z
Indexed on
2010/03/19
17:41 UTC
Read the original article
Hit count: 213
I'm not certain how to explain this with the correct terms so maybe an example is the best method...
$master = new MasterClass();
$master->doStuff();
class MasterClass {
var $a;
var $b;
var $c;
var $eventProccer;
function MasterClass()
{
$this->a = 1;
$this->eventProccer = new EventProcess();
}
function printCurrent()
{
echo '<br>'.$this->a.'<br>';
}
function doStuff()
{
$this->printCurrent();
$this->eventProccer->DoSomething();
$this->printCurrent();
}
}
class EventProcess {
function EventProcess() {}
function DoSomething()
{
// trying to access and change the parent class' a,b,c properties
}
}
My problem is i'm not certain how to access the properties of the MasterClass from within the EventProcess->DoSomething() method? I would need to access, perform operations on and update the properties. The a,b,c properties will be quite large arrays and the DoSomething() method would be called many times during the execuction of the script. Any help or pointers would be much appreciated :)
© Stack Overflow or respective owner