3v4l.org

run code in 300+ PHP versions simultaneously
<?php class foo { protected $bar = 'A bar'; public function getBarDumper() { return function() { var_dump($this->bar); }; } public static function getFactory() { // la fonction anonyme suivante est statique // car elle est déclarée dans une méthode statique. return function() { return new static(); }; } } $factory = foo::getFactory(); $reflectedFactory = new \reflectionFunction($factory); if ($reflectedFactory->getClosureThis() === null) echo "La fonction anonyme est statique" . PHP_EOL; $bar = $factory()->getBarDumper(); $reflectedBar = new \reflectionFunction($bar); if ($reflectedBar->getClosureThis() !== null) echo "La fonction anonyme n'est pas statique" . PHP_EOL;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 12
filename:       /in/NNuAk
function name:  (null)
number of ops:  27
compiled vars:  !0 = $factory, !1 = $reflectedFactory, !2 = $bar, !3 = $reflectedBar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_STATIC_METHOD_CALL                                  'foo', 'getFactory'
          1        DO_FCALL                                      0  $4      
          2        ASSIGN                                                   !0, $4
   20     3        NEW                                              $6      'reflectionFunction'
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $6
   21     7        INIT_METHOD_CALL                                         !1, 'getClosureThis'
          8        DO_FCALL                                      0  $9      
          9        TYPE_CHECK                                    2          $9
         10      > JMPZ                                                     ~10, ->12
         11    >   ECHO                                                     'La+fonction+anonyme+est+statique%0A'
   22    12    >   INIT_DYNAMIC_CALL                                        !0
         13        DO_FCALL                                      0  $11     
         14        INIT_METHOD_CALL                                         $11, 'getBarDumper'
         15        DO_FCALL                                      0  $12     
         16        ASSIGN                                                   !2, $12
   23    17        NEW                                              $14     'reflectionFunction'
         18        SEND_VAR_EX                                              !2
         19        DO_FCALL                                      0          
         20        ASSIGN                                                   !3, $14
   24    21        INIT_METHOD_CALL                                         !3, 'getClosureThis'
         22        DO_FCALL                                      0  $17     
         23        TYPE_CHECK                                  1020          $17
         24      > JMPZ                                                     ~18, ->26
         25    >   ECHO                                                     'La+fonction+anonyme+n%27est+pas+statique%0A'
         26    > > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FNNuAk%3A8%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NNuAk
function name:  {closure}
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   INIT_FCALL                                               'var_dump'
          1        FETCH_THIS                                       $0      
          2        FETCH_OBJ_R                                      ~1      $0, 'bar'
          3        SEND_VAL                                                 ~1
          4        DO_ICALL                                                 
          5      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FNNuAk%3A8%240

Function %00%7Bclosure%7D%2Fin%2FNNuAk%3A15%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NNuAk
function name:  {closure}
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   NEW                          static              $0      
          1        DO_FCALL                                      0          
          2      > RETURN                                                   $0
          3*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FNNuAk%3A15%241

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

End of function getbardumper

Function getfactory:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NNuAk
function name:  getFactory
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FNNuAk%3A15%241'
          1      > RETURN                                                   ~0
   16     2*     > RETURN                                                   null

End of function getfactory

End of class foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.04 ms | 1400 KiB | 15 Q