<?php
class MyClass
{
public $prop = "teste";
public function test()
{
$class = new class($this->prop) {
public function __construct($prop)
{
$this->prop = $prop;
}
public function run()
{
$this->prop = "teste na classe anĂ´nima";
echo $this->prop, PHP_EOL;
}
};
$class->run();
}
}
$obj = new MyClass();
$obj->test();
echo $obj->prop, PHP_EOL;
PD9waHAKCmNsYXNzIE15Q2xhc3MKewogICAgcHVibGljICRwcm9wID0gInRlc3RlIjsKCiAgICBwdWJsaWMgZnVuY3Rpb24gdGVzdCgpCiAgICB7CiAgICAgICAgJGNsYXNzID0gbmV3IGNsYXNzKCR0aGlzLT5wcm9wKSB7CgogICAgICAgICAgICBwdWJsaWMgZnVuY3Rpb24gX19jb25zdHJ1Y3QoJHByb3ApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICR0aGlzLT5wcm9wID0gJHByb3A7CiAgICAgICAgICAgIH0KCiAgICAgICAgICAgIHB1YmxpYyBmdW5jdGlvbiBydW4oKSAKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgJHRoaXMtPnByb3AgPSAidGVzdGUgbmEgY2xhc3NlIGFuw7RuaW1hIjsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZWNobyAkdGhpcy0+cHJvcCwgUEhQX0VPTDsKICAgICAgICAgICAgfQoKICAgICAgICB9OwoKICAgICAgICAkY2xhc3MtPnJ1bigpOwogICAgfQp9Cgokb2JqID0gbmV3IE15Q2xhc3MoKTsKJG9iai0+dGVzdCgpOwoKZWNobyAkb2JqLT5wcm9wLCBQSFBfRU9MOw==