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()); $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/WIK1E
function name:  (null)
number of ops:  46
compiled vars:  !0 = $closureInClass, !1 = $closureInTrait
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  13     0  E >   ADD_INTERFACE                                            'classconstanttest'
  25     1        INIT_STATIC_METHOD_CALL                                  'ClassConstantTest', 'getClosureInClass'
         2        DO_FCALL                                      0  $2      
         3        QM_ASSIGN                                                !0
  26     4        INIT_STATIC_METHOD_CALL                                  'ClassConstantTest', 'getClosureInTrait'
         5        DO_FCALL                                      0  $4      
         6        QM_ASSIGN                                                !1
  28     7        ASSIGN_OBJ                                               'Before+bind%3A+%0A'
  29     8        ASSIGN_OBJ                                               '__CLASS__+in+class%3A+%0A'
  30     9        INIT_FCALL                                               'var_dump'
        10        INIT_DYNAMIC_CALL                                        !0
        11        DO_FCALL                                      0  $6      
        12        SEND_VAR                                                 $6
        13        DO_ICALL                                                 
  31    14        ASSIGN_OBJ                                               '__CLASS__+in+Trait%3A+%0A'
  32    15        INIT_FCALL                                               'var_dump'
        16        INIT_DYNAMIC_CALL                                        !1
        17        DO_FCALL                                      0  $8      
        18        SEND_VAR                                                 $8
        19        DO_ICALL                                                 
  34    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        QM_ASSIGN                                                !0
  35    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        QM_ASSIGN                                                !1
  37    32        ASSIGN_OBJ                                               '%0AAfter+bind%3A+%0A'
  38    33        ASSIGN_OBJ                                               '__CLASS__+in+class%3A+%0A'
  39    34        INIT_FCALL                                               'var_dump'
        35        INIT_DYNAMIC_CALL                                        !0
        36        DO_FCALL                                      0  $14     
        37        SEND_VAR                                                 $14
        38        DO_ICALL                                                 
  40    39        ASSIGN_OBJ                                               '__CLASS__+in+Trait%3A+%0A'
  41    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%2FWIK1E0x7fcc0707a08e:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WIK1E
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%2FWIK1E0x7fcc0707a08e

Function %00%7Bclosure%7D%2Fin%2FWIK1E0x7fcc0707a13a:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WIK1E
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%2FWIK1E0x7fcc0707a13a

Class ClosureInATrait:
Function getclosureintrait:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WIK1E
function name:  getClosureInTrait
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   7     0  E >   RAISE_ABSTRACT_ERROR                             ~0      '%00%7Bclosure%7D%2Fin%2FWIK1E0x7fcc0707a08e'
   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/WIK1E
function name:  getClosureInClass
number of ops:  3
compiled vars:  none
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  19     0  E >   RAISE_ABSTRACT_ERROR                             ~0      '%00%7Bclosure%7D%2Fin%2FWIK1E0x7fcc0707a13a'
  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:
65.77 ms | 416 KiB | 7 Q