guyuehhh 发表于 2017-3-3 09:23:30

php类

<?php
class A
{
function f1()
{
if(isset($this)){
echo "is defined,".get_class($this)."\n";
}else{
echo "is not defined\n";
}
}
}
class B
{
function f2()
{
A::f1();
}
}
$a = new A;
$b = new B;
$a->f1();
A::f1();
$b->f2();
B::f2();
?>


is defined,A
is not defined
is defined,B
is not defined

<?php
class A
{
function f1()
{
echo "a1\n";
}
function f2()
{
echo "a2\n";
}
}
class B extends A
{
function f1()
{
echo "b1\n";
}
}
$a = new A();
$a->f1();
$b = new B();
$b->f1();
$b->f2();
?>

a1
b1
a2
页: [1]
查看完整版本: php类