fork download
  1. <?php
  2.  
  3. class MyClass
  4. {
  5. private $prop = "teste";
  6.  
  7. public function test()
  8. {
  9. $class = new class($this->prop) {
  10.  
  11. public function __construct($prop)
  12. {
  13. $this->prop = $prop;
  14. }
  15.  
  16. public function run()
  17. {
  18. echo $this->prop, PHP_EOL;
  19. }
  20.  
  21. };
  22.  
  23. $class->run();
  24. }
  25. }
  26.  
  27. $obj = new MyClass();
  28. $obj->test();
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
teste