function main3() { $obj = new C3(); // FPushObjMethodD $obj->__call("a", "b", "c", "d"); $obj->foo("a", "b", "c", "d"); // FPushObjMethod $fn = '__call'; $obj->{$fn}("a", "b", "c", "d"); $fn = 'foo'; $obj->{$fn}("a", "b", "c", "d"); }
function main3() { $obj = new C3(); $obj->test(); }
{ echo "B3::bar\n"; } public function baz() { $this->bar(); } } class C3 extends B3 { public function bar() { echo "C3::bar\n"; } } $obj = new C3(); $obj->baz(); class A4 { private function bar() { echo "A4::bar\n"; } } class B4 extends A4 { public function baz() { $this->bar(); } }
function m4() { echo "Inside " . __METHOD__ . "\n"; } } class C3 { use T3 { m1 as protected; // reduce visibility to future, derived classes m2 as private; m3 as public; m3 as protected z3; } } $c3 = new C3(); //$c3->m1(); // accessible, by default, but not once protected //$c3->m2(); // inaccessible, by default $c3->m3(); // inaccessible, by default $c3->m4(); // accessible, by default echo "===================== Traits using other Traits =========================\n"; trait Tx1 { function k() { echo "Inside " . __TRAIT__ . "\n"; echo "Inside " . __CLASS__ . "\n"; echo "Inside " . __METHOD__ . "\n"; }
$a = $b = $c = $d = 1; $e =& $x($a); $e = 2; var_dump($a); $e =& $x->__invoke($b); $e = 3; var_dump($b); $x($b); $x->__invoke($b); $x = function &(&$a) { return $a; }; $e =& $x($c); $e = 4; var_dump($c); $e =& $x->__invoke($d); $e = 5; var_dump($d); $x($d); $x->__invoke($d); $x = new C3(); var_dump($x()); var_dump($x->__invoke()); $x(); $x->__invoke(); $x = function () { }; var_dump($x()); var_dump($x->__invoke()); $x(); $x->__invoke();
} function __get($var) { echo "C8::__get({$var})\n"; return $this->g($var); } function g($var) { echo "C8::g({$var})\n"; return $this->{$var}; } } $c1 = new C1(); $c1->f1(); var_dump($a1); $c1->f2(); $c1->f3(); $c2 = new C2(); $c2->f1(); $c3 = new C3(); $c3->f1(); $c4 = new C4(); $c4->f1(); $c5 = new C5(); $c5->f1(); $c6 = new C6(); $c6->f1(); $c7 = new C7(); $c7->f1(); $c8 = new C8(); $c8->f1();