|
Posted by Markus Ernst on 09/05/05 20:54
Hello
In a content administration tool I call classes from inside classes in order
to separate the admin functions from the display-only functions:
class book
{
var $title;
var $author;
var $adminfunctions;
function book($admin = false)
{
if ($admin) {
$this->adminfunctions =& new book_admin($this);
}
}
function display_book()
{
return $this->author.": ".$this->title;
}
}
class book_admin
{
var $boss;
function book_admin(&$boss)
{
$this->boss = $boss;
}
function update_book($author, $title)
{
$this->boss->author = $author;
$this->boss->title = $title;
}
[lots of other methods]
}
The admin code will be something like:
$book =& new book(true);
$book->adminfunctions->update_book("Michael Crichton", "Jurassic Parc");
echo $book->display_book();
As you see there is a circle reference, as book_admin::boss is a reference
back to book. I assume this is bad, and actually there are some problems
that I suspect are originated there.
Is there another possibility to access properties of the calling object? I
did not find any syntax similar to the parent::property syntax, and I can't
use inheritance, as there is already a vertical inheritance (such as page
extends book extends library...), and it is not possible to inherit two
classes.
Thanks for a hint!
Markus
Navigation:
[Reply to this message]
|