访问类方法 [英] Accessing Class Method

查看:59
本文介绍了访问类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:


index.php:

class main_class {


public $ database = new DAL;

public $ html = new HTML;


}


dal.php:

类DAL {


函数方法(){

#Code

}


}


类HTML {


函数方法(){

#代码

#如何调用DAL的方法?

#Code

}


}


如你所见,DAL和HTML在两个类的两个变量中,但是

它们如何相互作用?

I have the following code:

index.php:
class main_class {

public $database = new DAL;
public $html = new HTML;

}

dal.php:
class DAL {

function method() {
# Code
}

}

class HTML {

function method() {
# Code
# HOW TO CALL DAL''S METHOD?
# Code
}

}

As you see, DAL and HTML are inside two variables of two classes, but
how can they interact with each other?

推荐答案

database = new DAL;

public
database = new DAL;
public


html = new HTML;


}


dal.php:

等级DAL {


函数方法(){

#Code

}


}


类HTML {


函数方法(){

#代码

#如何调用DAL的方法?

#Code

}


}


如您所见,DAL和HTML位于两个类的两个变量中,但是

他们如何互相交流?

html = new HTML;

}

dal.php:
class DAL {

function method() {
# Code
}

}

class HTML {

function method() {
# Code
# HOW TO CALL DAL''S METHOD?
# Code
}

}

As you see, DAL and HTML are inside two variables of two classes, but
how can they interact with each other?


他们无法互动,因为他们永远无法看到每一个其他。

如果你想使用当前的设置完成交互,

你必须在main_class类中编写方法,这将是

将信息从一个对象委托给另一个对象。


9月17日下午3:13,RageARC< rage ... @ gmail.comwrote:
They can''t interact, because they''ll never be able to see each other.
If you want to accomplish an interaction using your current setup,
you''ll have to write methods in the main_class class, which will
delegate information from one object to another.

On Sep 17, 3:13 pm, RageARC <rage...@gmail.comwrote:

我有以下代码:


index.php:

class main_class {

public
I have the following code:

index.php:
class main_class {

public


这篇关于访问类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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