3v4l.org

run code in 300+ PHP versions simultaneously
<?php function objectType($name, ...$fields) { if (empty($fields)) { throw new \RuntimeException(); } if (!is_string(key($fields[0]))) { $interfaces = array_shift($fields); } else { $interfaces = []; } if (empty($fields)) { throw new \RuntimeException(); } $def = [ 'name' => $name, 'interfaces' => $interfaces, 'fields' => [], ]; foreach ($fields as &$field) { $def['fields'][$field['name']] = $field; } return $def; } function field($name, $type, ...$args) { $def = [ 'name' => $name, 'type' => $type, 'args' => [], 'resolve' => null, ]; if (!empty($args) && is_callable(end($args))) { $def['resolve'] = array_pop($args); } foreach ($args as &$arg) { $def['args'][$arg['name']] = $arg; } return $def; } function argument($name, $type, $value = null) { $def = [ 'name' => $name, 'type' => $type, 'defaultValue' => $value, ]; return $def; } $IntType = ['name' => 'Int']; $StringType = ['name' => 'String']; $BlogType = objectType('Blog', field('id', $IntType), field('name', $StringType)); $UserType = objectType('Blog', field('id', $IntType, function () {}), field('email', $StringType)); $QueryType = objectType('Query', field('blog', $BlogType, argument('id', $IntType)), field('user', $UserType, argument('id', $IntType))); var_dump($QueryType);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QAr6Q
function name:  (null)
number of ops:  60
compiled vars:  !0 = $IntType, !1 = $StringType, !2 = $BlogType, !3 = $UserType, !4 = $QueryType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   ASSIGN                                                   !0, <array>
   61     1        ASSIGN                                                   !1, <array>
   63     2        INIT_FCALL                                               'objecttype'
          3        SEND_VAL                                                 'Blog'
   64     4        INIT_FCALL                                               'field'
          5        SEND_VAL                                                 'id'
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0  $7      
          8        SEND_VAR                                                 $7
   65     9        INIT_FCALL                                               'field'
         10        SEND_VAL                                                 'name'
         11        SEND_VAR                                                 !1
         12        DO_FCALL                                      0  $8      
         13        SEND_VAR                                                 $8
         14        DO_FCALL                                      0  $9      
   63    15        ASSIGN                                                   !2, $9
   67    16        INIT_FCALL                                               'objecttype'
         17        SEND_VAL                                                 'Blog'
   68    18        INIT_FCALL                                               'field'
         19        SEND_VAL                                                 'id'
         20        SEND_VAR                                                 !0
         21        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FQAr6Q%3A68%240'
         22        SEND_VAL                                                 ~11
         23        DO_FCALL                                      0  $12     
         24        SEND_VAR                                                 $12
   69    25        INIT_FCALL                                               'field'
         26        SEND_VAL                                                 'email'
         27        SEND_VAR                                                 !1
         28        DO_FCALL                                      0  $13     
         29        SEND_VAR                                                 $13
         30        DO_FCALL                                      0  $14     
   67    31        ASSIGN                                                   !3, $14
   71    32        INIT_FCALL                                               'objecttype'
         33        SEND_VAL                                                 'Query'
   72    34        INIT_FCALL                                               'field'
         35        SEND_VAL                                                 'blog'
         36        SEND_VAR                                                 !2
         37        INIT_FCALL                                               'argument'
         38        SEND_VAL                                                 'id'
         39        SEND_VAR                                                 !0
         40        DO_FCALL                                      0  $16     
         41        SEND_VAR                                                 $16
         42        DO_FCALL                                      0  $17     
         43        SEND_VAR                                                 $17
   73    44        INIT_FCALL                                               'field'
         45        SEND_VAL                                                 'user'
         46        SEND_VAR                                                 !3
         47        INIT_FCALL                                               'argument'
         48        SEND_VAL                                                 'id'
         49        SEND_VAR                                                 !0
         50        DO_FCALL                                      0  $18     
         51        SEND_VAR                                                 $18
         52        DO_FCALL                                      0  $19     
         53        SEND_VAR                                                 $19
         54        DO_FCALL                                      0  $20     
   71    55        ASSIGN                                                   !4, $20
   75    56        INIT_FCALL                                               'var_dump'
         57        SEND_VAR                                                 !4
         58        DO_ICALL                                                 
         59      > RETURN                                                   1

Function objecttype:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 125) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
2 jumps found. (Code = 126) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
Branch analysis from position: 25
filename:       /in/QAr6Q
function name:  objectType
number of ops:  39
compiled vars:  !0 = $name, !1 = $fields, !2 = $interfaces, !3 = $def, !4 = $field
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_VARIADIC                                    !1      
    4     2        ISSET_ISEMPTY_CV                                         !1
          3      > JMPZ                                                     ~5, ->7
    5     4    >   NEW                                              $6      'RuntimeException'
          5        DO_FCALL                                      0          
          6      > THROW                                         0          $6
    8     7    >   INIT_FCALL                                               'key'
          8        FETCH_DIM_R                                      ~8      !1, 0
          9        SEND_VAL                                                 ~8
         10        DO_ICALL                                         $9      
         11        TYPE_CHECK                                   64  ~10     $9
         12        BOOL_NOT                                         ~11     ~10
         13      > JMPZ                                                     ~11, ->19
    9    14    >   INIT_FCALL                                               'array_shift'
         15        SEND_REF                                                 !1
         16        DO_ICALL                                         $12     
         17        ASSIGN                                                   !2, $12
         18      > JMP                                                      ->20
   11    19    >   ASSIGN                                                   !2, <array>
   14    20    >   ISSET_ISEMPTY_CV                                         !1
         21      > JMPZ                                                     ~15, ->25
   15    22    >   NEW                                              $16     'RuntimeException'
         23        DO_FCALL                                      0          
         24      > THROW                                         0          $16
   19    25    >   INIT_ARRAY                                       ~18     !0, 'name'
   20    26        ADD_ARRAY_ELEMENT                                ~18     !2, 'interfaces'
   19    27        ADD_ARRAY_ELEMENT                                ~18     <array>, 'fields'
   18    28        ASSIGN                                                   !3, ~18
   24    29      > FE_RESET_RW                                      $20     !1, ->36
         30    > > FE_FETCH_RW                                              $20, !4, ->36
   25    31    >   FETCH_DIM_R                                      ~22     !4, 'name'
         32        FETCH_DIM_W                                      $21     !3, 'fields'
         33        ASSIGN_DIM                                               $21, ~22
         34        OP_DATA                                                  !4
   24    35      > JMP                                                      ->30
         36    >   FE_FREE                                                  $20
   28    37      > RETURN                                                   !3
   29    38*     > RETURN                                                   null

End of function objecttype

Function field:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 24
Branch analysis from position: 19
2 jumps found. (Code = 125) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
2 jumps found. (Code = 126) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 24
Branch analysis from position: 18
filename:       /in/QAr6Q
function name:  field
number of ops:  34
compiled vars:  !0 = $name, !1 = $type, !2 = $args, !3 = $def, !4 = $arg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_VARIADIC                                    !2      
   33     3        INIT_ARRAY                                       ~5      !0, 'name'
   34     4        ADD_ARRAY_ELEMENT                                ~5      !1, 'type'
   33     5        ADD_ARRAY_ELEMENT                                ~5      <array>, 'args'
          6        ADD_ARRAY_ELEMENT                                ~5      null, 'resolve'
   32     7        ASSIGN                                                   !3, ~5
   39     8        ISSET_ISEMPTY_CV                                 ~7      !2
          9        BOOL_NOT                                         ~8      ~7
         10      > JMPZ_EX                                          ~8      ~8, ->18
         11    >   INIT_FCALL                                               'is_callable'
         12        INIT_FCALL                                               'end'
         13        SEND_REF                                                 !2
         14        DO_ICALL                                         $9      
         15        SEND_VAR                                                 $9
         16        DO_ICALL                                         $10     
         17        BOOL                                             ~8      $10
         18    > > JMPZ                                                     ~8, ->24
   40    19    >   INIT_FCALL                                               'array_pop'
         20        SEND_REF                                                 !2
         21        DO_ICALL                                         $12     
         22        ASSIGN_DIM                                               !3, 'resolve'
         23        OP_DATA                                                  $12
   43    24    > > FE_RESET_RW                                      $13     !2, ->31
         25    > > FE_FETCH_RW                                              $13, !4, ->31
   44    26    >   FETCH_DIM_R                                      ~15     !4, 'name'
         27        FETCH_DIM_W                                      $14     !3, 'args'
         28        ASSIGN_DIM                                               $14, ~15
         29        OP_DATA                                                  !4
   43    30      > JMP                                                      ->25
         31    >   FE_FREE                                                  $13
   47    32      > RETURN                                                   !3
   48    33*     > RETURN                                                   null

End of function field

Function argument:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QAr6Q
function name:  argument
number of ops:  9
compiled vars:  !0 = $name, !1 = $type, !2 = $value, !3 = $def
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   52     3        INIT_ARRAY                                       ~4      !0, 'name'
   53     4        ADD_ARRAY_ELEMENT                                ~4      !1, 'type'
   54     5        ADD_ARRAY_ELEMENT                                ~4      !2, 'defaultValue'
   51     6        ASSIGN                                                   !3, ~4
   57     7      > RETURN                                                   !3
   58     8*     > RETURN                                                   null

End of function argument

Function %00%7Bclosure%7D%2Fin%2FQAr6Q%3A68%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QAr6Q
function name:  {closure}
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   68     0  E > > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FQAr6Q%3A68%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.52 ms | 1411 KiB | 36 Q