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->adminfunctio ns =& new book_admin($thi s);
}
}
function display_book()
{
return $this->author.": ".$this->title;
}
}
class book_admin
{
var $boss;
function book_admin(&$bo ss)
{
$this->boss = $boss;
}
function update_book($au thor, $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->adminfunctio ns->update_book("M ichael Crichton", "Jurassic Parc");
echo $book->display_book() ;
As you see there is a circle reference, as book_admin::bos s 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::propert y 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
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->adminfunctio ns =& new book_admin($thi s);
}
}
function display_book()
{
return $this->author.": ".$this->title;
}
}
class book_admin
{
var $boss;
function book_admin(&$bo ss)
{
$this->boss = $boss;
}
function update_book($au thor, $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->adminfunctio ns->update_book("M ichael Crichton", "Jurassic Parc");
echo $book->display_book() ;
As you see there is a circle reference, as book_admin::bos s 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::propert y 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
Comment