<?php class a{ function test1(){ echo "hello"; } }class b extends a{ var $var_a; function b(){ $this->var_a = new a(); }}class c{ var $var_b; function c(){ $b = new b(); $b->var_a->test1();//这样调用为什么会出错 } } $p = new c;?>
是我错了 引用正确的方法如下 :) <?php class a{ function test1(){ echo "你好"; } }class b extends a{ var $var_a; function b(){ $this->var_a = new a(); }}class c{ var $var_b; function c(&$b){ $this->var_b=$b; $this->var_b->test1(); } } $s = new b; $p = new c(&$s);?>这样就可以使用一些机制去扩展类和对象了 :) 结贴
class a{
function test1(){
echo "hello";
}
}class b extends a{
var $var_a;
function b(){
$this->var_a = new a();
}}class c{
var $var_b;
function c(){
$b = new b();
$b->var_a->test1();//这样调用为什么会出错
}
}
$p = new c;?>
<?php
class a{
function test1(){
echo "你好";
}
}class b extends a{
var $var_a;
function b(){
$this->var_a = new a();
}}class c{
var $var_b;
function c(&$b){
$this->var_b=$b;
$this->var_b->test1();
}
}
$s = new b;
$p = new c(&$s);?>这样就可以使用一些机制去扩展类和对象了 :) 结贴