3v4l.org

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

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

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

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

End of function %00%7Bclosure%7D%2Fin%2F5vgBc%3A19%241

Class ClosureInATrait:
Function getclosureintrait:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5vgBc
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%2F5vgBc%3A7%240'
    9     1      > RETURN                                                   ~0
   10     2*     > RETURN                                                   null

End of function getclosureintrait

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/5vgBc
function name:  getClosureInClass
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F5vgBc%3A19%241'
   21     1      > RETURN                                                   ~0
   22     2*     > RETURN                                                   null

End of function getclosureinclass

End of class ClassConstantTest.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.9 ms | 1404 KiB | 15 Q