<?php header('Content-Type:text/html; charset=utf-8'); class A{ const c = "ConstA"; public function m(){ echo self::c; } } class B extends A{ const c="constB"; } $b = new B(); $b->m(); ?>
<?php trait T { public function m() { echo "original\n"; } } class A { use T; } class B { use T; } T::m(); $a1 = new A(); $a1->m(); fb_intercept("T::m", function () { echo "new\n"; }); $a2 = new A(); $a2->m(); $b1 = new B(); $b1->m(); T::m();
<?php /* */ header('Content-Type:text/html; charset=utf-8'); class A{ const c = "ConstA"; public function m(){ echo self::c; } } class B extends A{ const c="constB"; } $b = new B(); $b->m(); //输出ConstA ?>