public static function test() { // FPushClsMethodD C::foo("a", "b", "c", "d"); // FPushClsMethod $cls = 'C'; $cls::foo("a", "b", "c", "d"); $fn = 'foo'; C::$fn("a", "b", "c", "d"); $fn = 'foo'; $cls::$fn("a", "b", "c", "d"); // FPushClsMethodF self::foo("a", "b", "c", "d"); }
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 class C { function foo() { if ($this) { return true; } else { return false; } } } var_dump(C::foo());
public static function callByParent() { parent::foo(); }
<?php // Copyright 2004-2015 Facebook. All Rights Reserved. echo "Starting\n"; class C { public function foo() { echo "foo\n"; $x = array(); if ($x) { print_r($x); } else { print_r($x); } } } $c = new C(); $val = $c->foo(); echo $val; echo "\n"; echo "Done\n";
<?php trait T { function foo() { echo "Foo"; $this->bar(); } abstract function bar(); } class C { use T; function bar() { echo "BAR!\n"; } } $x = new C(); $x->foo();
{ function foo($x, $y = 0); } interface J { function foo($x, $y); } interface K { function foo($x, $y = 0, array $z); } interface L { function foo($x, $y, array $z = null); } interface M { function foo($x, $y = 0, array $z = array()); } class C implements I, J, K, L, M { public function foo($x, $y = 0, array $z = null, array $a = null) { echo "{$x} {$y} {$z}\n"; } } $obj = new C(); $obj->foo(1); $obj->foo(1, 2); $obj->foo(1, 2, null); $obj->foo(1, 2, array());
<?php class A { public $a = null; } class B extends A { public function foo() { var_dump($this->a); } } class C extends B { public $a = 'test'; } $obj = new C(); $obj->foo();
<?php // Method invocation on $this class C { function foo($x, $y) { echo "C::foo({$x}, {$y})\n"; $this->bar($y, $x); } function bar($x, $y) { echo "C::bar({$x}, {$y})\n"; } } $c = new C(); $c->foo(1, 2);
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 abstract class A { public abstract function foo(int $x); } interface I { function foo(int $x); } abstract class B extends A implements I { } class C extends B { public function foo(array $x = null) { } } $c = new C(); $c->foo(null); echo "OK\n";
function bar() { C::foo(); }
function main() { return B::foo() + C::foo(); }
<?php class C { public $y = 5; function foo($x) { return $x + $this->y; } } $o = new C(); echo $o->foo(3) . "\n";
<?php class C { /** * @param string * @param array */ public function __call($method, $args) { } } $c = new C(); $c->foo('asdf');
} public function foo($x) { $bar = function ($y) use($x) { return $this->stuff($x, $y); }; return $bar(33); } public function bar($x) { $zeta = new_model($x); return function ($y) use($zeta) { return $this->stuff($y, $zeta); }; } } function lam($b) { $fn = function ($a) use($b) { return $a + $b; }; $gn = function ($a) use($b) { $c = $b * 20; return $a + $b; }; return $fn(10) + $gn(10); } var_dump(lam(42)); $c = new C(); var_dump($c->foo(20));
function bar() { $obj = new C(); $obj->foo(123); }
<?php class C { public function foo($x, $str) { $y = $str ?: "Water"; return $y . ": " . ($x < 100 ? ($x < 30 ? "cold" : "warm") . " water" : ($x > 200 ? "OMG" : "steam")); } } $c = new C(); echo $c->foo(17, "") . "\n";
<?php print "Test begin\n"; interface I { public static function foo(); } class C implements I { public static function foo($x) { echo 'Hello ' . $x . "\n"; } } C::foo("5"); print "Test end\n";
<?php print "Test begin\n"; interface I { public function foo($x, $y); } class C implements I { public function foo($x) { echo 'Hello ' . $x . "\n"; } } $o = new C(); $o->foo("5"); print "Test end\n";
<?php trait T { public abstract function foo($x); } interface I { public function foo($x); } abstract class B implements I { use T; } class C extends B { public function foo($x) { echo "{$x} \n"; } } $obj = new C(); $obj->foo(1);
function foo() { $k = new C(); $k->foo(); }
<?php trait T { public abstract function bar(); public function foo() { $this->bar(); } } class B { public function bar() { echo "I'm bar\n"; } } class C extends B { use T; } $o = new C(); $o->foo();
<?php trait T1 { abstract function foo(); } trait T2 { abstract function foo(); } abstract class B { use T1, T2; } class C extends B { function foo() { return "hello\n"; } } $o = new C(); echo $o->foo();
<?php abstract class A { protected abstract function foo(); } class B extends A { protected function foo() { echo "B::foo\n"; } } class C extends A { function foo() { $b = new B(); $b->foo(); } } $c = new C(); $c->foo();
<?php class C { var $x; function __construct($x) { $this->x = $x; } function foo($that) { var_dump($this->x); $this = $that; var_dump($this->x); } } $c1 = new C(1); $c2 = new C(2); $c1->foo($c2);
<?php abstract class C { static abstract function foo(); } function foo(callable $x) { } try { C::foo(); } catch (Error $e) { echo "\nException: " . $e->getMessage() . " in ", $e->getFile() . " on line " . $e->getLine() . "\n"; } try { foo("C::foo"); } catch (Error $e) { echo "\n"; do { echo "Exception: " . $e->getMessage() . "\n"; $e = $e->getPrevious(); } while ($e instanceof Error); } C::foo();
<?php abstract class A { public abstract function foo(int $x); } class B extends A { public function foo(int $x) { } } class C extends B { public function foo(array $x) { } } $o = new C(); $o->foo(array()); echo "OK\n";
{ echo $str . "\n"; } class Bar { public function bar() { return "zing"; } public function baz($other) { echo $this === $other ? "me\n" : "not me\n"; } public function garply($n, $s, $b) { echo \hacklib_cast_as_boolean($b) ? $s : $n; echo "\n"; } } class C { public function foo($x) { other_func("and now: " . \hacklib_nullsafe($x)->bar()); \hacklib_nullsafe($x)->baz($x); \hacklib_nullsafe($x)->garply(1, "hi", true); } } $c = new C(); $c->foo(new Bar()); $c->foo(null);
<?php class C { public static function foo() { return "world\n"; } public static $foo = "hello"; } echo C::$foo; echo C::foo();