3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Kitchen { private $yummy = 'cake'; } class Mapper { public function map(Kitchen $kitchen, array $data) { $mapper = $this; $map = function (Kitchen $kitchen, array $data) use ($mapper) { $mapper->setYummy($kitchen, $data); }; $map = Closure::bind($map, null, $kitchen); $map($kitchen, $data); } public function setYummy(Kitchen $kitchen, array $data) { $kitchen->yummy = $data['yummy']; } } $kitchen = new Kitchen; $mapper = new Mapper; $mapper->map($kitchen, ['yummy' => 'cookie']); var_dump($kitchen); /* $sweetsThief = function (Kitchen $kitchen) { return $kitchen->yummy; }; $sweetsCop = function (Kitchen $kitchen, $yummy) { $kitchen->yummy = $yummy; }; $kitchen = new Kitchen(); $sweetsThief = Closure::bind($sweetsThief, null, $kitchen); $sweetsCop = Closure::bind($sweetsCop, null, $kitchen); var_dump($sweetsThief($kitchen)); $sweetsCop($kitchen, 'lie'); var_dump($sweetsThief($kitchen)); */
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oK89U
function name:  (null)
number of ops:  14
compiled vars:  !0 = $kitchen, !1 = $mapper
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   NEW                                              $2      'Kitchen'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   29     3        NEW                                              $5      'Mapper'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   30     6        INIT_METHOD_CALL                                         !1, 'map'
          7        SEND_VAR_EX                                              !0
          8        SEND_VAL_EX                                              <array>
          9        DO_FCALL                                      0          
   31    10        INIT_FCALL                                               'var_dump'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                                 
   51    13      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FoK89U%3A14%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oK89U
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $kitchen, !1 = $data, !2 = $mapper
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   15     3        INIT_METHOD_CALL                                         !2, 'setYummy'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
   16     7      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FoK89U%3A14%240

Class Kitchen: [no user functions]
Class Mapper:
Function map:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oK89U
function name:  map
number of ops:  18
compiled vars:  !0 = $kitchen, !1 = $data, !2 = $mapper, !3 = $map
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        FETCH_THIS                                       ~4      
          3        ASSIGN                                                   !2, ~4
   14     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FoK89U%3A14%240'
          5        BIND_LEXICAL                                             ~6, !2
          6        ASSIGN                                                   !3, ~6
   18     7        INIT_STATIC_METHOD_CALL                                  'Closure', 'bind'
          8        SEND_VAR                                                 !3
          9        SEND_VAL                                                 null
         10        SEND_VAR                                                 !0
         11        DO_FCALL                                      0  $8      
         12        ASSIGN                                                   !3, $8
   19    13        INIT_DYNAMIC_CALL                                        !3
         14        SEND_VAR_EX                                              !0
         15        SEND_VAR_EX                                              !1
         16        DO_FCALL                                      0          
   20    17      > RETURN                                                   null

End of function map

Function setyummy:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oK89U
function name:  setYummy
number of ops:  6
compiled vars:  !0 = $kitchen, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   24     2        FETCH_DIM_R                                      ~3      !1, 'yummy'
          3        ASSIGN_OBJ                                               !0, 'yummy'
          4        OP_DATA                                                  ~3
   25     5      > RETURN                                                   null

End of function setyummy

End of class Mapper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.75 ms | 1400 KiB | 15 Q