3v4l.org

run code in 300+ PHP versions simultaneously
<?php function applyDocumentCasts($keyPattern, Closure $closure) { $casts = [ 'unchanged' => fn ($item) => $item, 'object' => fn ($item) => (object) $item, // 'Serializable' => fn ($item) => new BSONDocument($item), // 'Document' => fn ($item) => Document::fromPHP($item), ]; return array_combine( array_map(fn ($castName) => sprintf($keyPattern, $castName), array_keys($casts)), array_map(fn ($cast) => $closure($cast), $casts), ); } function provideFilterDocuments(): array { $expectedQuery = (object) ['x' => 1]; return applyDocumentCasts( '%s', fn ($cast) => [$cast(['x' => 1]), $expectedQuery] ); } var_dump(provideFilterDocuments());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AXNBq
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'providefilterdocuments'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        DO_ICALL                                                 
          5      > RETURN                                                   1

Function applydocumentcasts:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AXNBq
function name:  applyDocumentCasts
number of ops:  28
compiled vars:  !0 = $keyPattern, !1 = $closure, !2 = $casts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          3        INIT_ARRAY                                       ~4      ~3, 'unchanged'
    7     4        DECLARE_LAMBDA_FUNCTION                          ~5      [1]
          5        ADD_ARRAY_ELEMENT                                ~4      ~5, 'object'
    5     6        ASSIGN                                                   !2, ~4
   12     7        INIT_FCALL                                               'array_combine'
   13     8        INIT_FCALL                                               'array_map'
          9        DECLARE_LAMBDA_FUNCTION                          ~7      [2]
         10        BIND_LEXICAL                                             ~7, !0
         11        SEND_VAL                                                 ~7
         12        INIT_FCALL                                               'array_keys'
         13        SEND_VAR                                                 !2
         14        DO_ICALL                                         $8      
         15        SEND_VAR                                                 $8
         16        DO_ICALL                                         $9      
         17        SEND_VAR                                                 $9
   14    18        INIT_FCALL                                               'array_map'
         19        DECLARE_LAMBDA_FUNCTION                          ~10     [3]
         20        BIND_LEXICAL                                             ~10, !1
         21        SEND_VAL                                                 ~10
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                         $11     
         24        SEND_VAR                                                 $11
   12    25        DO_ICALL                                         $12     
   14    26      > RETURN                                                   $12
   16    27*     > 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/AXNBq
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1      > RETURN                                                   !0
          2*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AXNBq
function name:  {closure}
number of ops:  4
compiled vars:  !0 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        CAST                                          8  ~1      !0
          2      > RETURN                                                   ~1
          3*     > RETURN                                                   null

End of Dynamic Function 1

Dynamic Function 2
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AXNBq
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $castName, !1 = $keyPattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_FCALL                                               'sprintf'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
          7*     > RETURN                                                   null

End of Dynamic Function 2

Dynamic Function 3
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AXNBq
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $cast, !1 = $closure
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_DYNAMIC_CALL                                        !1
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
          6*     > RETURN                                                   null

End of Dynamic Function 3

End of function applydocumentcasts

Function providefilterdocuments:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AXNBq
function name:  provideFilterDocuments
number of ops:  12
compiled vars:  !0 = $expectedQuery
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   CAST                                          8  ~1      <array>
          1        ASSIGN                                                   !0, ~1
   22     2        INIT_FCALL                                               'applydocumentcasts'
   23     3        SEND_VAL                                                 '%25s'
   24     4        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
          5        BIND_LEXICAL                                             ~3, !0
   25     6        SEND_VAL                                                 ~3
   22     7        DO_FCALL                                      0  $4      
   25     8        VERIFY_RETURN_TYPE                                       $4
          9      > RETURN                                                   $4
   26    10*       VERIFY_RETURN_TYPE                                       
         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/AXNBq
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $cast, !1 = $expectedQuery
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_DYNAMIC_CALL                                        !0
          3        SEND_VAL_EX                                              <array>
          4        DO_FCALL                                      0  $2      
          5        INIT_ARRAY                                       ~3      $2
          6        ADD_ARRAY_ELEMENT                                ~3      !1
          7      > RETURN                                                   ~3
   25     8*     > RETURN                                                   null

End of Dynamic Function 0

End of function providefilterdocuments

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.23 ms | 1013 KiB | 20 Q