嵌套对象之间的引用(PHP4) [英] References between nested objects (PHP4)

查看:37
本文介绍了嵌套对象之间的引用(PHP4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好


在内容管理工具中,我从类内部调用类,以便将管理功能与仅显示功能分开:

: br />

班级书籍

{

var $ title;

var $ author;

var $ adminfunctions;


功能书($ admin = false)

{

if($ admin) {

$ this-> adminfunctions =& new book_admin($ this);

}

}


function display_book()

{

返回$ this-> author。":"。$ this-> title;

}

}


class book_admin

{

var $ boss;


function book_admin(& $老板)

{

$ this-> boss = $ boss;

}


function update_book($ author,$ title)

{

$ this-> boss-> author = $ author;

$ this - > boss-> title = $ title;

}


[很多其他方法]

}


管理员代码如下:


$ book =&新书(true);

$ book-> adminfunctions-> update_book(" Michael Crichton"," Jurassic Parc");

echo $ book- > display_book();


如你所见,有一个圆圈参考,因为book_admin :: boss是一个参考

重新预订。我认为这很糟糕,实际上有一些问题

我怀疑是在那里发生的。


还有另一种可能性来访问调用对象的属性?我没有找到类似于parent :: property语法的语法,而且我不能使用继承,因为已经存在垂直继承(例如页面

扩展图书扩展库...),并且不可能继承两个

类。


谢谢你提示!

Markus

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

推荐答案

title;

var
title;
var


作者;

var
author;
var


adminfunctions;


函数手册(
adminfunctions;

function book(


这篇关于嵌套对象之间的引用(PHP4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆