function &a($arg) { return parent::a($arg); }
class foo { public $x = 2; public function a() { $x = array(); $x[] = new foo(); return $x; } public function b() { return array(1.2, array(new self())); } public function c() { $a = array(); $b =& $a; $b[] = true; return $a; } public function d() { return $this->b(); } } $foo = new foo(); var_dump($foo->a()[0]->x); var_dump($foo->a()[0]); var_dump($foo->b()[1][0]->a()[0]->x); var_dump($foo->c()[0]); var_dump($foo->d()[0]);
<?php class foo { public function a() { } } $test = new foo(); $test->a()->a; print "ok\n"; $test->a()->a = 1; print "ok\n";
class foo { private function a() { var_dump(1); } public function b() { var_dump(2); } protected function c() { var_dump(3); } static function __callstatic($a, $b) { var_dump('__callStatic::' . $a); } public function __call($a, $b) { var_dump('__call::' . $a); } } $x = new foo(); $x->a(); $x->b(); $x->c(); $x::a(); $x::b(); $x::c();
<?php class foo { public static function a() { print "ok\n"; } } $a = 'a'; $b = 'a'; $class = 'foo'; foo::a(); foo::$a(); foo::${$b}(); $class::a(); $class::$a(); $class::${$b}();
<?php class foo { static $x = array(); public function &a() { self::$x = array(1, 2, 3); return self::$x; } public function b() { $x = array(1); $x[] = 2; return $x; } } $foo = new foo(); // Changing the static variable $foo->a()[0] = 2; var_dump($foo::$x); $foo->b()[] = new stdClass(); $h = $foo->b(); var_dump($h); $h[0] = 3; var_dump($h);
<?php error_reporting(E_ALL); class foo { public $arr; public function &a() { return $this->arr; } } $foo = new foo(); $h =& $foo->a(); $h[] = 1; $h[] = $foo; var_dump($foo->a()[1]->arr[1]->a()[1]->arr[1]->arr[0]); var_dump($foo->a()[1]); var_dump($foo->a()[1]->arr[1]);
<?php error_reporting(E_ALL); class foo { public $x; public static $y; public function a() { return $this->x; } public static function b() { return self::$y; } } $foo = new foo(); $h = $foo->a()[0]->a; var_dump($h); $h = foo::b()[1]->b; var_dump($h);