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();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/clICI
function name:  (null)
number of ops:  7
compiled vars:  !0 = $my
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   DECLARE_CLASS                                            'mytest', 'testcase'
   36     1        NEW                                              $1      'MyTest'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
   37     4        INIT_METHOD_CALL                                         !0, 'runBare'
          5        DO_FCALL                                      0          
          6      > RETURN                                                   1

Class TestCase:
Function yesorno:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/clICI
function name:  yesOrNo
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                   <false>
          1*     > RETURN                                                   null

End of function yesorno

Function runbare:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/clICI
function name:  runBare
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   INIT_METHOD_CALL                                         'doThePostConditionHook'
          1        DO_FCALL                                      0          
   11     2        INIT_FCALL                                               'printf'
          3        SEND_VAL                                                 'We+did+%25d+tests'
          4        FETCH_OBJ_R                                      ~1      'num'
          5        SEND_VAL                                                 ~1
          6        DO_ICALL                                                 
   12     7      > RETURN                                                   null

End of function runbare

End of class TestCase.

Class ImmaExtendThis:
Function dothepostconditionhook:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/clICI
function name:  doThePostConditionHook
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ECHO                                                     '%0A'
   22     1        PRE_INC_OBJ                                              'num'
   23     2      > RETURN                                                   null

End of function dothepostconditionhook

Function brutalnumworkaround:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/clICI
function name:  brutalNumWorkaround
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   NEW                                              $0      'ReflectionProperty'
          1        SEND_VAL_EX                                              'TestCase'
          2        SEND_VAL_EX                                              'num'
          3        DO_FCALL                                      0          
          4        INIT_METHOD_CALL                                         $0, 'setAccessible'
          5        SEND_VAL_EX                                              <true>
          6        DO_FCALL                                      0          
   27     7      > RETURN                                                   null

End of function brutalnumworkaround

End of class ImmaExtendThis.

Class MyTest: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.97 ms | 1015 KiB | 14 Q