fork download
  1. <?php
  2.  
  3. class MyClass
  4. {
  5. public $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. $this->prop = "teste na classe anĂ´nima";
  19.  
  20. echo $this->prop, PHP_EOL;
  21. }
  22.  
  23. };
  24.  
  25. $class->run();
  26. }
  27. }
  28.  
  29. $obj = new MyClass();
  30. $obj->test();
  31.  
  32. echo $obj->prop, PHP_EOL;
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
teste na classe anônima
teste