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__;
- protected $y = __CLASS__;
- public function test()
- {
- echo "\tget_class(\$this): " . get_class($this) . PHP_EOL;
- echo "\tget_class():" . get_class() . PHP_EOL;
- echo "\tmethod: " . __METHOD__ . PHP_EOL;
- echo "\t\$this->x: " . $this->x . PHP_EOL;
- echo "\t\$this->y: " . $this->y . PHP_EOL;
- // return static::$x; // Fatal error: Cannot access private property Bclass::$x
- return $this->x;
- }
- }
- class Bclass extends Aclass
- {
- private $x = __CLASS__;
- protected $y = __CLASS__;
- }
- $bObj = new Bclass();
- echo '$bObj = new Bclass();' . PHP_EOL;
- echo 'get_class($bObj) => ' . get_class($bObj) . PHP_EOL;
- echo '$bObj->test()' . PHP_EOL;
- $bObj->test();
- echo PHP_EOL;
- echo '\\Closure::bind(function() { return $this->test(); }, new Aclass(), $bObj)->__invoke()' . PHP_EOL;
- \Closure::bind(function() { return $this->test(); }, new Aclass(), $bObj)->__invoke();
- echo PHP_EOL;
- echo '\Closure::bind(function() { return $this->test(); }, $bObj, $bObj)->__invoke()' . PHP_EOL;
- \Closure::bind(function() { return $this->test(); }, $bObj, $bObj)->__invoke();
- echo PHP_EOL;
- // PHP Fatal error: Uncaught Error: Cannot access private property Aclass::$x
- // $aObj = new Aclass();
- // $aObj->testBase();
- /**
- OUTPUT:
- $bObj = new Bclass();
- get_class($bObj) => Bclass
- $bObj->test()
- get_class($this): Bclass
- get_class():Aclass
- method: Aclass::test
- $this->x: Aclass
- $this->y: Bclass
- \Closure::bind(function() { return $this->test(); }, new Aclass(), $bObj)->__invoke()
- get_class($this): Aclass
- get_class():Aclass
- method: Aclass::test
- $this->x: Aclass
- $this->y: Aclass
- \Closure::bind(function() { return $this->test(); }, $bObj, $bObj)->__invoke()
- get_class($this): Bclass
- get_class():Aclass
- method: Aclass::test
- $this->x: Aclass
- $this->y: Bclass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement