function test_call_method_dataflow() { $o = new B(); $o->foo(1, 2); //SKIP: requires dataflow (simple here, but still) $o->foo(); }
function test() { $a = new A(); echo $a->foo(); $a = new B(); echo $a->foo(555); echo $a->foo(); }
function bar() { $obj = new A(); $obj->foo(123); $obj = new B(); $obj->foo(123, 456); }
function bar() { $obj = new A(); $obj->foo(); $obj = new B(); $obj->foo(); }
public function foo2() { B::foo(); // B always changes 'static' self::foo(); // 'self' doesn't change 'static' }
public static function test() { $arr = array('foo'); self::foo(); parent::foo(); self::$arr[0](); parent::$arr[0](); echo self::MYCONST . "\n"; echo parent::MYCONST . "\n"; }
function main() { $x = null; if (true) { $x = new A(); } else { $x = new B(); } //TODO: it should call both methods ... $x->foo(); //var_dump($x); }
<?php class A { } class AA extends A { function test() { print 'AA ok'; } } class B { function foo(A $obj) { $obj->test(); } } $obj = new AA(); $b = new B(); $b->foo($obj);
{ print "A::baz\n"; } private function f() { echo "A::f\n"; } public function g($a) { echo "A::g\n"; $a->f(); } } class B extends A { protected function bar() { print "B::bar\n"; $this->baz(); } public function h($a) { print "B::g\n"; $a->f(); } } $a = new A(); $b = new B(); $b->foo(); $b->g($a); #$b->h($a);
function main() { $b = new B(); $b->foo(); }
<?php class A { protected static $foo = 11; function foo() { var_dump(A::$foo); } } class B extends A { public static $foo; } var_dump(B::$foo); B::$foo = 123; A::foo();
<?php // Make sure that we can tell which class was called for intercepted static // methods class A { public function foo() { echo 'foo called'; } } class B extends A { } fb_intercept('A::foo', function ($_, $called_on) { var_dump($called_on); }); A::foo(); B::foo(); // Trigger run_intercept_handler_for_invokefunc codepath $class = 'B'; $c = 'call_user_fun'; $c .= 'c'; $c(array($class, 'foo'));
<?php // including scripts example include "a.php"; require_once "b.php"; f(12345); $a = new A("AAA"); $a->write(); $a->foo("hello"); $a->write(); $b = new B("BBB"); $b->write(); $b->foo("bye"); $b->write(); fgets(STDIN);
<?php class A { function foo() { $f = static function () { return self::class; }; return $f(); } } class B extends A { } $b = new B(); var_dump($b->foo());
<?php require "tests.php"; require "overload_return_type.php"; $b = new B(); check::equal($b->foo(1), 0, ""); check::classname("A", $b->foo("test")); check::equal(overload_return_type::foo(), 1, "overload_return_type::foo() should be 1"); check::equal(overload_return_type::bar(), 1, "overload_return_type::bar() should be 1");
<?php class A { public function foo(array $x) { return 1; } } class B extends A { //override public function foo($x) { return 2; } } $o = new B(); $o->foo(4);
function foo() { $b = new B(); $b->foo(); }
function test_method() { $o = new B(); $o->foo(1, 2); }
function main() { return B::foo() + C::foo(); }
<?php class A { public function foo() { echo "A::foo()\n"; } } class B extends A { public function __call($f, $args) { echo "B::__call({$f}, {$args})\n"; } } $o = new B(); // this will call A::foo. The __call is used only when // nothing was found in the whole hierarchy, not just // when nothing was found in your class. $o->foo(); // this will call B::__call $o->bar();
$class = get_called_class(); (yield $class); } public function foo() { return self::gen(); } } class B extends A { } function t($x) { foreach ($x as $v) { var_dump($v); } } t(B::sgen()); t(B::sfoo()); t(A::sgen()); t(A::sfoo()); t(B::gen()); t(B::foo()); t(A::gen()); t(A::foo()); $b = new B(); t($b->gen()); t($b->foo()); $a = new A(); t($a->gen()); t($a->foo());
function main() { $b = new B(); $b->foo(); var_dump($b); }
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 class A { function test() { print 'A'; } function foo() { $this->test(); } } class B extends A { function test() { print 'B'; } } $obj = new A(); $obj = new B(); $obj->foo();
} ?> --FILE-- <?php class A { function foo($arg1 = 1) { } } class B extends A { function foo($arg1 = 2, $arg2 = 3) { var_dump($arg1); var_dump($arg2); } } class C extends A { function foo() { } } $b = new B(); $b->foo(1); // TODO: Strict Standards: Declaration of C::foo() should be compatible with A::foo($arg1 = 1) in %s on line %d ?> --EXPECTF-- int(1) int(3)
[expect exact] ahoj [file] <?php include "b.inc"; class C extends B { } $x = new B(); $x->x = "ahoj"; $x->foo();
<?php class A { static function foo() { $f = static function () { return static::class; }; return $f(); } } class B extends A { } var_dump(B::foo());