December 25, 2008
class ap {
public function ap_call() {
echo "\t", get_called_class(), "\n";
}
public function ap_sub_call_p() {
$p = new p;
$p->p_call();
}
public function ap_sub_call_c() {
$c = new c;
$c->c_call();
}
}
class p extends ap{
public function p_call() {
echo "\t", get_called_class(), "\n";
}
public function p_parent_call_ap() {
$ap = new ap;
$ap->ap_call();
}
public function p_sub_call_c() {
$c = new c;
$c->c_call();
}
}
class c extends p {
public function c_call() {
echo "\t", get_called_class(), "\n";
}
public function c_parent_call_p() {
$p = new p;
$p->p_call();
}
public function c_parent_call_ap() {
$ap = new ap;
$ap->ap_call();
}
}
$ap = new ap;
$p = new p;
$c = new c;
echo "These are called in/from ap:\n";
$ap->ap_call();
$ap->ap_sub_call_p();
$ap->ap_sub_call_c();
echo "\n\nThese are called in/from p:\n";
$p->p_call();
$p->p_parent_call_ap();
$p->p_sub_call_c();
echo "These are inherit from ap:\n";
$p->ap_call();
$p->ap_sub_call_p();
$p->ap_sub_call_c();
echo "\n\nhese are called in/from c:\n";
$c->c_call();
$c->c_parent_call_ap();
$c->c_parent_call_p();
echo "These are inherit from p:\n";
$c->p_call();
$c->p_parent_call_ap();
$c->p_sub_call_c();
echo "These are inherit from ap:\n";
$c->ap_call();
$c->ap_sub_call_p();
$c->ap_sub_call_c();
/*
result:
These are called in/from ap:
ap
p
c
These are called in/from p:
p
ap
c
These are inherit from ap:
p
p
c
hese are called in/from c:
c
ap
p
These are inherit from p:
c
ap
c
These are inherit from ap:
c
p
c
*/
No comments:
Post a Comment