3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SomeHelperClass { // Version 1 public static function getProperty1(object $object, string $property) { return Closure::bind( function () use ($property) { return $this->$property; }, $object, $object )(); } // Version 2 public static function getProperty2(object $object, string $property) { return ( function () use ($property) { return $this->$property; } )->bindTo( $object, $object )->__invoke(); } } class Test { private $property = 'test1'; private $property2 = 'test2'; } $object = new Test; echo SomeHelperClass::getProperty1($object, 'property'); echo SomeHelperClass::getProperty2($object, 'property2');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GVu23
function name:  (null)
number of ops:  14
compiled vars:  !0 = $object
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   NEW                                              $1      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   38     3        INIT_STATIC_METHOD_CALL                                  'SomeHelperClass', 'getProperty1'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 'property'
          6        DO_FCALL                                      0  $4      
          7        ECHO                                                     $4
   39     8        INIT_STATIC_METHOD_CALL                                  'SomeHelperClass', 'getProperty2'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 'property2'
         11        DO_FCALL                                      0  $5      
         12        ECHO                                                     $5
         13      > RETURN                                                   1

Class SomeHelperClass:
Function getproperty1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GVu23
function name:  getProperty1
number of ops:  13
compiled vars:  !0 = $object, !1 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
    9     3        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          4        BIND_LEXICAL                                             ~2, !1
   11     5        SEND_VAL                                                 ~2
   12     6        SEND_VAR                                                 !0
   13     7        SEND_VAR                                                 !0
    8     8        DO_FCALL                                      0  $3      
   13     9        INIT_DYNAMIC_CALL                                        $3
   14    10        DO_FCALL                                      0  $4      
   13    11      > RETURN                                                   $4
   15    12*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GVu23
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   BIND_STATIC                                              !0
   10     1        FETCH_THIS                                       $1      
          2        FETCH_OBJ_R                                      ~2      $1, !0
          3      > RETURN                                                   ~2
   11     4*     > RETURN                                                   null

End of Dynamic Function 0

End of function getproperty1

Function getproperty2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GVu23
function name:  getProperty2
number of ops:  12
compiled vars:  !0 = $object, !1 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        DECLARE_LAMBDA_FUNCTION                          ~2      [0]
          3        BIND_LEXICAL                                             ~2, !1
   24     4        INIT_METHOD_CALL                                         ~2, 'bindTo'
   25     5        SEND_VAR_EX                                              !0
          6        SEND_VAR_EX                                              !0
   24     7        DO_FCALL                                      0  $3      
   27     8        INIT_METHOD_CALL                                         $3, '__invoke'
          9        DO_FCALL                                      0  $4      
         10      > RETURN                                                   $4
   28    11*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GVu23
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $property
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   BIND_STATIC                                              !0
   22     1        FETCH_THIS                                       $1      
          2        FETCH_OBJ_R                                      ~2      $1, !0
          3      > RETURN                                                   ~2
   23     4*     > RETURN                                                   null

End of Dynamic Function 0

End of function getproperty2

End of class SomeHelperClass.

Class Test: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.62 ms | 1000 KiB | 13 Q