3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestCase { private $num; private function yesOrNo() { return false; } public function runBare() { // simulating https://github.com/sebastianbergmann/phpunit/blob/9.1.5/src/Framework/TestCase.php#L1035 $this->doThePostConditionHook(); printf('We did %d tests', $this->num); } } trait ImmaExtendThis { /** * @postCondition */ protected function doThePostConditionHook() { echo '' . PHP_EOL; $this->num++; } private function brutalNumWorkaround() { (new ReflectionProperty(TestCase::class, 'num'))->setAccessible(true); } } class MyTest extends TestCase { use ImmaExtendThis; // ... } $my = new MyTest(); $my->runBare();

preferences:
14.55 ms | 404 KiB | 5 Q