function foo() { $a = new A(); $a->foo(); $a->field = 123; $a->foo(); }
function bar() { $obj = new A(); $obj->foo(123); $obj = new B(); $obj->foo(123, 456); }
public function foo3() { $this->foo(); // $this changes 'static' parent::foo(); // 'parent' doesn't change 'static' }
function foo() { $a = new A(); $a->foo(); $a->bar(); # $a->baz(); }
function bar() { $obj = new A(); $obj->foo(); $obj = new B(); $obj->foo(); }
static function __callstatic($name, $args) { parent::__callstatic($name, $args); call_user_func_array("parent::__callstatic", array($name, $args)); parent::foo(); call_user_func_array("parent::foo", $args); call_user_func_array(array("parent", "foo"), $args); }
function test() { $a = new A(); echo $a->foo(); $a = new B(); echo $a->foo(555); echo $a->foo(); }
public static function test() { A::foo(); // non-forwarding call, A::foo self::foo(); // forwarding call, C::foo parent::foo(); // forwarding call, C::foo }
public function foo() { $a = new A(); $a->foo(); $b = new Boo(); $b->foo(); $c = new Clo(); $c->foo(); }
public function doFoo() { $this->foo(); // B B B B::foo(); // B B B C::foo(); // C C (Zend outputs: C B B) (Rule 1) D::foo(); // D D (Zend outputs: D B B) (Rule 1) F::foo(); // F F (Zend outputs: F B B) (Rule 1) G::foo(); // G G (Zend outputs: G B B) (Rule 1) H::foo(); // H H (Zend outputs: H B B) (Rule 1) parent::foo(); // A B B self::foo(); // B B B static::foo(); // B B B echo "****************\n"; }
<?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 class A { private $a = 0; protected $b = 0; public $c = 0; function foo() { var_dump($this->a, $this->b, $this->c); } function bar() { echo __METHOD__ . "\n"; var_dump($this->a, $this->b, $this->c); } } class B extends A { public $a = 1; public $b = 1; public $c = 1; function foo() { var_dump($this->a, $this->b, $this->c); } } $x = new A(); $x->foo(); $x = new B(); $x->foo(); $x->bar();
<?php class A { static function foo() { return function () { }; } } $a = A::foo(); $a->bindTo(new A()); echo "Done.\n";
<?php $a = 1; if (empty(foo($a))) { } if (empty($a->foo($a))) { } if (empty($foo($a))) { } if (empty(A::foo($a))) { } if (empty($a)) { } if (empty(array())) { } if (empty([''])) { } if (empty(${a})) { } function foo($a) { return true; }
<?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 { public function foo() { } public $bar0 = 0; public $bar1 = 1; } $a = new A(); $b = array(0 => 'A', 1 => 'B'); list($a->bar0, $a->bar1) = $b; list($a->foo(), $a->bar1) = $b;
<?php trait T { public function goo() { return get_called_class(); } public function foo() { return self::goo(); } } class A { use T; } var_dump(A::goo()); var_dump(A::foo());
function bar() { A::foo(); }
class A { public function __call($method, $args) { foreach ($args as $a) { var_dump($a); } var_dump(array_pop($args)); if (isset($args[1])) { var_dump($args[1]); } reset($args); if (key($args) === 0) { $args = array(5); } if (current($args) === 0) { $args = array(5); } if (next($args) === 0) { $args = array(5); } var_dump($args['1']); var_dump($args['hi']); $args = $args + array(2 => 0, 3 => true, 4 => true); var_dump($args); } } $obj = new A(); $obj->foo(1, 2, 3);
function bar() { // Nota: la siguiente línea arrojará una advertencia si E_STRICT está habilitado. A::foo(); }
<?php class A { public function foo($a) { echo __FUNCTION__ . "\n"; } } $x = 1; $a = new A(); $a->foo(&$x);
public static function test($a1) { A::foo($a1); self::foo($a1); }
function boo() { A::foo(); }
public function test() { A::foo(); }
<?php class A { public function foo() { $values = array(1, 2, 3); $values = array_map(function ($p) { return $this->goo($p); }, $values); var_dump($values); } public function bar() { return $this; } public function goo($p) { return $p; } } $obj = new A(); var_dump($obj->bar()); $obj->foo();
public static function test() { A::foo(); parent::foo(); self::foo(); }
<?php require "tests.php"; require "exception_order.php"; check::functions(array(a_foo, a_bar, a_foobar, a_barfoo)); check::classes(array(A, E1, E2, E3, exception_order, ET_i, ET_d)); check::globals(array(efoovar, foovar, cfoovar, a_sfoovar, a_foovar, a_efoovar)); $a = new A(); try { $a->foo(); } catch (Exception $e) { check::equal($e->getMessage(), 'C++ E1 exception thrown', ''); } try { $a->bar(); } catch (Exception $e) { check::equal($e->getMessage(), 'C++ E2 exception thrown', ''); } try { $a->foobar(); } catch (Exception $e) { check::equal($e->getMessage(), 'postcatch unknown', ''); } try { $a->barfoo(1); } catch (Exception $e) { check::equal($e->getMessage(), 'C++ E1 exception thrown', ''); } try { $a->barfoo(2); } catch (Exception $e) {
{ function &foo(&$n, $p) { global $a; $n = 123; $p += 1; var_dump('foo'); return $a; } } class B { function &bar(&$n, $p) { global $b; $n = 456; $p += 2; var_dump('bar'); return $b; } } function fb_stubout_intercept_handler($name, $obj, $params, $data, $done) { return call_user_func($data, $params); } fb_intercept('A::foo', 'fb_stubout_intercept_handler', 'B::bar'); $n = 0; $d = 3; $c =& A::foo($n, $d); var_dump($c, $d); $c = 30;
function t7(A $o) { return $o->foo("bar"); }
function main(A $a) { var_dump($a->foo()); }