function main() { $c = new C(); B::test($c); C::test($c); D::test($c); }
function main() { $a = new A(); $b = new B(); $c = new C(); B::test($a); C::test($b); E::test($c); }
} } class B { use T2 { t2method as Bmethod; } } class C extends A { } trait T1 { protected function backtrace() { $b = new B(); $b->Bmethod(); } } trait T2 { public function t2method() { print_r(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1)); } } $a = new A(); $a->test(); $c = new C(); $c->test();
<?php define("FOO", 123); trait T { private $blah = FOO; public function test() { var_dump($this->blah); } } class C { use T; } $obj = new C(); $obj->test();
<?php class C { public function test() { unset($this); return get_defined_vars(); } } $c = new C(); $x = $c->test(); print_r($x); unset($c, $x);
class C { /** * @return self */ function f() { return $this; } /** * @return static */ function g() { return $this; } /** * @return $this */ function h() { return $this; } function test(C $c) { } } $c = new C(); $f = $c->test($c->f()); $g = $c->test($c->g()); $h = $c->test($c->h());
public static function foo() { static::who(); } public static function who() { echo __CLASS__ . "\n"; } } class B extends A { public static function test() { A::foo(); parent::foo(); self::foo(); } public static function who() { echo __CLASS__ . "\n"; } } class C extends B { public static function who() { echo __CLASS__ . "\n"; } } C::test();
function main() { $c = new C(); $c->test(); }
function main() { $obj = new C(); $obj->test(); }
<?php class A { public static function test($x = null) { if (!is_null($x)) { echo "{$x}\n"; } return get_called_class(); } } class B extends A { } class C extends A { } class D extends A { } echo A::test(B::test(C::test(D::test()))) . "\n"; ?> ==DONE==
var_dump(get_object_vars($b)); } } class C extends B { private $hiddenPriv = 'C::hiddenPriv'; public static function test($b) { echo __METHOD__ . "\n"; var_dump(get_object_vars($b)); } } class X { public static function test($b) { echo __METHOD__ . "\n"; var_dump(get_object_vars($b)); } } $b = new B(); echo "\n---( Global scope: )---\n"; var_dump(get_object_vars($b)); echo "\n---( Declaring class: )---\n"; B::test($b); echo "\n---( Subclass: )---\n"; C::test($b); echo "\n---( Superclass: )---\n"; A::test($b); echo "\n---( Unrelated class: )---\n"; X::test($b);
function main() { $c = new C(); $c->test(); echo "Done\n"; }
function main() { $b = new B(); $c = new C(); $c->test($b); }
class D { public static function who() { echo "D\n"; } } class E extends D { public static function who() { echo "E\n"; } } $o = new C(); $o->test(); class O { public function who() { echo "O\n"; } } class P extends O { function __toString() { return '$this'; } public function who() {