Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Base
- {
- public function testBase()
- {
- var_dump(__METHOD__ . ' is ran from: ' . get_class($this));
- return $this->x;
- }
- }
- class Aclass extends Base
- {
- private $x = __CLASS__;
- public function test()
- {
- var_dump(__METHOD__ . ' is ran as: ' . get_class($this));
- return $this->x;
- }
- }
- class Bclass
- extends Aclass
- {
- private $x = __CLASS__;
- }
- $bObj = new Bclass();
- var_dump($bObj, $bObj->test());
- echo '===========' . PHP_EOL;
- \Closure::bind(function() { return $this->test(); }, new Aclass(), $bObj)->__invoke();
- //force a context change
- \Closure::bind(function() { return $this->test(); }, $bObj, $bObj)->__invoke();
- echo '===========' . PHP_EOL;
- $aObj = new Aclass();
- $aObj->testBase();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement