3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait ClosureInATrait { public static function getConstInTrait() { return __CLASS__; } } class ClassConstantTest { use ClosureInATrait; public static function getConstInClass() { return __CLASS__; } } $closureInClass = (new ReflectionMethod('ClassConstantTest','getConstInClass'))->getClosure(); $closureInTrait = (new ReflectionMethod('ClassConstantTest','getConstInTrait'))->getClosure(); echo 'Before bind: ' . PHP_EOL; echo '__CLASS__ in class: ' . PHP_EOL; var_dump($closureInClass()); echo '__CLASS__ in Trait: ' . PHP_EOL; var_dump($closureInTrait()); $closureInClass = Closure::bind($closureInClass, null, 'stdClass'); $closureInTrait = Closure::bind($closureInTrait, null, 'stdClass'); echo PHP_EOL . 'After bind: ' . PHP_EOL; echo '__CLASS__ in class: ' . PHP_EOL; var_dump($closureInClass()); echo '__CLASS__ in Trait: ' . PHP_EOL; var_dump($closureInTrait());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EhVlW
function name:  (null)
number of ops:  54
compiled vars:  !0 = $closureInClass, !1 = $closureInTrait
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   DECLARE_CLASS                                            'classconstanttest'
   21     1        NEW                                              $2      'ReflectionMethod'
          2        SEND_VAL_EX                                              'ClassConstantTest'
          3        SEND_VAL_EX                                              'getConstInClass'
          4        DO_FCALL                                      0          
          5        INIT_METHOD_CALL                                         $2, 'getClosure'
          6        DO_FCALL                                      0  $4      
          7        ASSIGN                                                   !0, $4
   22     8        NEW                                              $6      'ReflectionMethod'
          9        SEND_VAL_EX                                              'ClassConstantTest'
         10        SEND_VAL_EX                                              'getConstInTrait'
         11        DO_FCALL                                      0          
         12        INIT_METHOD_CALL                                         $6, 'getClosure'
         13        DO_FCALL                                      0  $8      
         14        ASSIGN                                                   !1, $8
   24    15        ECHO                                                     'Before+bind%3A+%0A'
   25    16        ECHO                                                     '__CLASS__+in+class%3A+%0A'
   26    17        INIT_FCALL                                               'var_dump'
         18        INIT_DYNAMIC_CALL                                        !0
         19        DO_FCALL                                      0  $10     
         20        SEND_VAR                                                 $10
         21        DO_ICALL                                                 
   27    22        ECHO                                                     '__CLASS__+in+Trait%3A+%0A'
   28    23        INIT_FCALL                                               'var_dump'
         24        INIT_DYNAMIC_CALL                                        !1
         25        DO_FCALL                                      0  $12     
         26        SEND_VAR                                                 $12
         27        DO_ICALL                                                 
   30    28        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         29        SEND_VAR                                                 !0
         30        SEND_VAL                                                 null
         31        SEND_VAL                                                 'stdClass'
         32        DO_FCALL                                      0  $14     
         33        ASSIGN                                                   !0, $14
   31    34        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         35        SEND_VAR                                                 !1
         36        SEND_VAL                                                 null
         37        SEND_VAL                                                 'stdClass'
         38        DO_FCALL                                      0  $16     
         39        ASSIGN                                                   !1, $16
   33    40        ECHO                                                     '%0AAfter+bind%3A+%0A'
   34    41        ECHO                                                     '__CLASS__+in+class%3A+%0A'
   35    42        INIT_FCALL                                               'var_dump'
         43        INIT_DYNAMIC_CALL                                        !0
         44        DO_FCALL                                      0  $18     
         45        SEND_VAR                                                 $18
         46        DO_ICALL                                                 
   36    47        ECHO                                                     '__CLASS__+in+Trait%3A+%0A'
   37    48        INIT_FCALL                                               'var_dump'
         49        INIT_DYNAMIC_CALL                                        !1
         50        DO_FCALL                                      0  $20     
         51        SEND_VAR                                                 $20
         52        DO_ICALL                                                 
         53      > RETURN                                                   1

Class ClosureInATrait:
Function getconstintrait:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EhVlW
function name:  getConstInTrait
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   FETCH_CLASS_NAME                                 ~0      
          1      > RETURN                                                   ~0
    8     2*     > RETURN                                                   null

End of function getconstintrait

End of class ClosureInATrait.

Class ClassConstantTest:
Function getconstinclass:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/EhVlW
function name:  getConstInClass
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E > > RETURN                                                   'ClassConstantTest'
   18     1*     > RETURN                                                   null

End of function getconstinclass

End of class ClassConstantTest.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.96 ms | 1400 KiB | 15 Q