3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait ClosureInATrait { public static function getClosureInTrait() { return function () { return [__CLASS__, self::boo()]; }; } public static function boo() { return __METHOD__; } } class ClassConstantTest { use ClosureInATrait; public static function getClosureInClass() { return function () { return [__CLASS__, self::class]; }; } public static function boo() { return __METHOD__; } } $closureInClass = ClassConstantTest::getClosureInClass(); $closureInTrait = ClassConstantTest::getClosureInTrait(); 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/RXI8l
function name:  (null)
number of ops:  46
compiled vars:  !0 = $closureInClass, !1 = $closureInTrait
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   DECLARE_CLASS                                            'classconstanttest'
   35     1        INIT_STATIC_METHOD_CALL                                  'ClassConstantTest', 'getClosureInClass'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !0, $2
   36     4        INIT_STATIC_METHOD_CALL                                  'ClassConstantTest', 'getClosureInTrait'
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !1, $4
   38     7        ECHO                                                     'Before+bind%3A+%0A'
   39     8        ECHO                                                     '__CLASS__+in+class%3A+%0A'
   40     9        INIT_FCALL                                               'var_dump'
         10        INIT_DYNAMIC_CALL                                        !0
         11        DO_FCALL                                      0  $6      
         12        SEND_VAR                                                 $6
         13        DO_ICALL                                                 
   41    14        ECHO                                                     '__CLASS__+in+Trait%3A+%0A'
   42    15        INIT_FCALL                                               'var_dump'
         16        INIT_DYNAMIC_CALL                                        !1
         17        DO_FCALL                                      0  $8      
         18        SEND_VAR                                                 $8
         19        DO_ICALL                                                 
   44    20        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         21        SEND_VAR                                                 !0
         22        SEND_VAL                                                 null
         23        SEND_VAL                                                 'stdClass'
         24        DO_FCALL                                      0  $10     
         25        ASSIGN                                                   !0, $10
   45    26        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
         27        SEND_VAR                                                 !1
         28        SEND_VAL                                                 null
         29        SEND_VAL                                                 'stdClass'
         30        DO_FCALL                                      0  $12     
         31        ASSIGN                                                   !1, $12
   47    32        ECHO                                                     '%0AAfter+bind%3A+%0A'
   48    33        ECHO                                                     '__CLASS__+in+class%3A+%0A'
   49    34        INIT_FCALL                                               'var_dump'
         35        INIT_DYNAMIC_CALL                                        !0
         36        DO_FCALL                                      0  $14     
         37        SEND_VAR                                                 $14
         38        DO_ICALL                                                 
   50    39        ECHO                                                     '__CLASS__+in+Trait%3A+%0A'
   51    40        INIT_FCALL                                               'var_dump'
         41        INIT_DYNAMIC_CALL                                        !1
         42        DO_FCALL                                      0  $16     
         43        SEND_VAR                                                 $16
         44        DO_ICALL                                                 
         45      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FRXI8l%3A7%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RXI8l
function name:  {closure}
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   FETCH_CLASS_NAME                                 ~0      
          1        INIT_ARRAY                                       ~1      ~0
          2        INIT_STATIC_METHOD_CALL                                  'boo'
          3        DO_FCALL                                      0  $2      
          4        ADD_ARRAY_ELEMENT                                ~1      $2
          5      > RETURN                                                   ~1
    9     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FRXI8l%3A7%240

Function %00%7Bclosure%7D%2Fin%2FRXI8l%3A24%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RXI8l
function name:  {closure}
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   INIT_ARRAY                                       ~0      'ClassConstantTest'
          1        FETCH_CLASS_NAME                                 ~1      
          2        ADD_ARRAY_ELEMENT                                ~0      ~1
          3      > RETURN                                                   ~0
   26     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FRXI8l%3A24%241

Class ClosureInATrait:
Function getclosureintrait:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RXI8l
function name:  getClosureInTrait
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FRXI8l%3A7%240'
    9     1      > RETURN                                                   ~0
   10     2*     > RETURN                                                   null

End of function getclosureintrait

Function boo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RXI8l
function name:  boo
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E > > RETURN                                                   'ClosureInATrait%3A%3Aboo'
   15     1*     > RETURN                                                   null

End of function boo

End of class ClosureInATrait.

Class ClassConstantTest:
Function getclosureinclass:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RXI8l
function name:  getClosureInClass
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FRXI8l%3A24%241'
   26     1      > RETURN                                                   ~0
   27     2*     > RETURN                                                   null

End of function getclosureinclass

Function boo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RXI8l
function name:  boo
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E > > RETURN                                                   'ClassConstantTest%3A%3Aboo'
   32     1*     > RETURN                                                   null

End of function boo

End of class ClassConstantTest.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.99 ms | 1404 KiB | 15 Q