fork download
  1. <?php
  2.  
  3. class Target {
  4. public $var = 'Target var';
  5. }
  6.  
  7. class Test {
  8. public $leftAttribute = 'var';
  9. public function run() {
  10. $target = new Target;
  11. echo $target->var, PHP_EOL;
  12. echo $this->leftAttribute, PHP_EOL;
  13. echo $target->{$this->leftAttribute};
  14. }
  15. }
  16.  
  17. (new Test)->run();
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
Target var
var
Target var