是否可以将$this对象分配给扩展$this基类的类的新实例??(当然是在php中)
class base {
function a() {
// do some stuff here
$extended = new extending();
$this = $extended;
$this->extended_functionality();
}
}
class extending {
function extended_functionality() {
// do some more! stuff here
}
}发布于 2011-09-09 10:17:29
简而言之。不是的。
$this是表示当前实例化对象的只读关键字。
只需首先创建您想要的对象即可。
发布于 2015-03-02 19:27:32
不,您应该:
class base {
private extended;
function a() {
// do some stuff here
$this->extended = new extending();
$this->extended->extended_functionality();
}
}
class extending {
function __construct() {
}
function extended_functionality() {
// do some more! stuff here
}
}https://stackoverflow.com/questions/7356481
复制相似问题