public function __construct() { parent::A(); // NOK parent::f(); // OK }
function main() { $a = new A(); $a->foo = 12; $a->f(); inOtherUnit(1, 2); }
$x =& $z; return $x; } public function g() { global $z; $x =& $z; return $x; } } function f() { global $z; $x =& $z; return $x; } function g(&$x) { $x[] = 1; } $z = array(1); $a = new A(); g(f()); __var_dump($z); g(A::f()); __var_dump($z); $g = "g"; $g(A::f()); __var_dump($z); g($a->g()); __var_dump($z);
<?php class A { function f() : int { return 42; } } class B { function g() : string { return 'string'; } } $a = new A(); print $a->g(); print $a->f(); $a = new B(); print $a->g(); print $a->f();
<?php class A { public function f($x) { var_dump($x()); var_dump(get_class()); } } $a = new A(); $a->f('get_class'); var_dump(get_class($a)); var_dump(get_class()); var_dump(get_class(null));
[expect php] [file] <?php $a = array(""); $a[0][0] = "f"; var_dump($a); $a = array("bubu"); @($a[0][0] = "xyz"); var_dump($a); class C { public $f; } $c = new C(); $c->f = "kuku"; $c->f[2] = "x"; var_dump($c); class B { static $f; } B::$f = "hello"; B::$f[3] = "x"; var_dump(B::$f); eval('class A { static $f; }'); A::$f = "hello"; A::$f[3] = "x"; var_dump(A::$f);
} } interface I { public function a(int $a1 = 0); public function b(array $b1 = null); } class B implements I { public function a(int $a1 = null, int $z1 = 1, int $z2 = D2, int $z3 = 3, int $z4 = null) { } public function b(array $b1 = null, array $y = array(), int $z1 = 1, int $z2 = 2, double $z3 = 3.0, string $z4 = "abc") { } } $a = new A(); $a->a(); $a->b(); $a->d(); $a->f(); $a->i(); $a->s(); $a->c(); $a->c($a); $a->c(null); $a->z(); $b = new B(); $b->a(); $b->b(); print "Pass\n";
<?php // This test validates phan checking the types of params passed to assert() class A { public static function f() : bool { return false; } } assert(!A::f(), 'string'); assert(10 > 1, 'string');
[EXPECT] g [FILE] <?php class A { static function f() { function v() { class B { static function g() { echo __FUNCTION__; } } B::g(); } v(); } } A::f();
<?php class A { function f($a) { } } $obj = new A(); $obj->f(date('m/d/y H:i:s', 123456789)); $v = date("m", 123456789) + 1;
<?php class A { function f($a) { var_dump($a === null); } } $a = true; $a = new A(); $a->f(array());
<?php class A { static function f() { return new static(); } static function g($o) { return $o instanceof static; } } class B extends A { } var_dump(A::g(A::f())); var_dump(A::g(B::f())); var_dump(B::g(A::f())); var_dump(B::g(B::f()));
function test() { $a = new A(); $a->f(); var_dump($a); }
<?php if (class_exists('B')) { class A extends B { public function f() { var_dump('A'); } } } var_dump(class_exists('C')); class B extends C { public function f() { var_dump('B'); } } class C { } if (class_exists('A')) { $obj = new A(); $obj->f(); } else { var_dump('correct'); }
<?php $a = 'self'; class A { public static function f($value) { $filter = 'g'; return call_user_func(array($GLOBALS['a'], $filter), $value); } public static function g($value) { return $value; } } var_dump(A::f('test'));
<?php // The first of a set of test cases establishing how magic methods are used. // We also want to determine how the internals object handlers are used. class A { function __get($x) { echo "get\n"; } function __call($a, $b) { var_dump($a, $b); echo "call\n"; } } $x = new A(); $y = new A(); $a = new A(); $a = $x + $y; $a = $x - $y; $a = $x * $y; $a = $x / $y; $a = $x < $y; $a = $x >= $y; $x->f();
<?php trait T { function f() { $a = function () { (yield 1); (yield 2); }; return $a; } } class A { use T; } $a = new A(); $f = $a->f(); foreach ($f() as $v) { var_dump($v); }
<?php function f($arg0, $arg1) { var_dump($arg0, $arg1); } function g(&$arg0, $arg1) { var_dump($arg0, $arg1); } class A { function f($f, $var) { $f($this, ${$var} = 5); } function g($f, $var) { $f($this, $var++); } } $a = new A(); $a->f('f', 'this'); $a->f('g', 'this'); $a->g('f', 30); $a->g('g', 30);
function f() { parent::f(); }
function f() { echo "B::f -- this: |" . get_class($this) . "|\n"; A::f(); }