OOP Class Interaction
| From: | Jonathan Pitcher | Date: | Wed, 31 Mar 2004 17:55:32 +0000 |
| Subject: | OOP Class Interaction | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-181961@lists.php.net to get a copy of this message | ||
I have been writing OOP programs for the past couple years. Over these years I have run into the same problem, I have solved the problem in many different ways. I was wondering if there is a recommended way to solve the problem I have listed below.
To keep it simple, lets say I have 3 classes. A main class, an error class and a log class.
The classes are laid out as:
MAIN
|
----------------
| |
ERROR LOG
Now I want error to write a message to the log file.
Solution 1
Store the Main class in a Session variable. And the access the Log through main.
$_SESSION["Main"]->Log->Write_Error("My Error");
Solution 2
Almost the same as above. I store main in a Session Variable but the I create a global function to access log.
function Write_Error($Message)
{
$_SESSION["Main"]->Log->Write_Error($Message);
}
This ways saves coding time because I don't have to write out the long session reference.
I know there are more ways to do this. But every way I can think of requires you to store the main class in a session variable to access log. Is there a way to access a parent class or a parents parent without doing what I did above ?
Thanks in advance,
Jonathan Pitcher