function main() { $c = new C(); $d = new D(); $c->foo(); $d->foo(); echo "**************\n"; $c->bar(); $d->bar(); echo "**************\n"; C::foo(); D::bar(); echo "**************\n"; $d->yar(); D::yar(); }
<?php // Invocation of a static class method of a superclass // Class *definition* is interpreted eval(<<<PHP \tclass C \t{ \t\tstatic function foo() \t\t{ \t\t\techo "C::foo() "; \t\t} \t} \tclass D extends C \t{ \t} PHP ); D::foo();
} } class D extends C { static $cls = 'D'; public function __construct() { var_dump(isset($this)); var_dump(static::$cls); } public function yar() { var_dump(isset($this)); var_dump(static::$cls); C::yar(); } } $c = new C(); $d = new D(); echo "**************\n"; $c->foo(); $d->foo(); echo "**************\n"; $c->bar(); $d->bar(); echo "**************\n"; C::foo(); D::bar(); echo "**************\n"; $d->yar(); D::yar();
public function test() { // This should not call C::foo, it should fatal D::foo(); }
<?php trait T { static function foo() { echo "I'm in class " . get_class() . "\n"; } } class C { use T; } class D extends C { } trait T2 { use T; } trait T3 { use T2; } $x = new D(); $x->foo(); C::foo(); D::foo(); T::foo(); T2::foo(); T3::foo();
public function doFoo() { $this->foo(); // G G G B::foo(); // B B (Zend: B G G) (Rule 1) C::foo(); // C C (Zend: C G G) (Rule 1) D::foo(); // D D (Zend: D G G) (Rule 1) F::foo(); // F G G G::foo(); // G G G H::foo(); // H H (Zend: H G G) (Rule 1) parent::foo(); // F G G self::foo(); // G G G static::foo(); // G G G echo "****************\n"; }
<?php interface I { function foo(); } abstract class B implements I { } abstract class C extends B { } class D extends C { public function foo() { echo "Done\n"; } } $obj = new D(); $obj->foo();
public function test() { $this->foo(); D::foo(); E::foo(); }