3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Name implements \Stringable { public function __construct(public readonly string $name) { } public function __toString(): string { return $this->name; } } enum Value: string { case id = 'id'; } function create(\WeakMap $map): \WeakMap { $name = new Name('func'); if (!isset($map[$name])) { $map[$name] = 'func-val'; } echo "In function scope:\n\n"; var_dump($map); echo PHP_EOL; return $map; } $name = new Name('global'); $map = new \WeakMap(); $map[$name] = 'global-val'; $map = create($map); echo "\n"; echo "In global scope:\n\n"; // watch the `Name('func')` key not being present here var_dump($map);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TSO37
function name:  (null)
number of ops:  21
compiled vars:  !0 = $name, !1 = $map
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'name'
   15     1        DECLARE_CLASS                                            'value'
   33     2        NEW                                              $2      'Name'
          3        SEND_VAL_EX                                              'global'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $2
   34     6        NEW                                              $5      'WeakMap'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $5
   35     9        ASSIGN_DIM                                               !1, !0
         10        OP_DATA                                                  'global-val'
   36    11        INIT_FCALL                                               'create'
         12        SEND_VAR                                                 !1
         13        DO_FCALL                                      0  $9      
         14        ASSIGN                                                   !1, $9
   38    15        ECHO                                                     '%0A'
   39    16        ECHO                                                     'In+global+scope%3A%0A%0A'
   41    17        INIT_FCALL                                               'var_dump'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function create:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/TSO37
function name:  create
number of ops:  19
compiled vars:  !0 = $map, !1 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   22     1        NEW                                              $2      'Name'
          2        SEND_VAL_EX                                              'func'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !1, $2
   23     5        ISSET_ISEMPTY_DIM_OBJ                         0  ~5      !0, !1
          6        BOOL_NOT                                         ~6      ~5
          7      > JMPZ                                                     ~6, ->10
   24     8    >   ASSIGN_DIM                                               !0, !1
          9        OP_DATA                                                  'func-val'
   26    10    >   ECHO                                                     'In+function+scope%3A%0A%0A'
   27    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                                 
   28    14        ECHO                                                     '%0A'
   29    15        VERIFY_RETURN_TYPE                                       !0
         16      > RETURN                                                   !0
   30    17*       VERIFY_RETURN_TYPE                                       
         18*     > RETURN                                                   null

End of function create

Class Name:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TSO37
function name:  __construct
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        ASSIGN_OBJ                                               'name'
          2        OP_DATA                                                  !0
    7     3      > RETURN                                                   null

End of function __construct

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/TSO37
function name:  __toString
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   FETCH_OBJ_R                                      ~0      'name'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   12     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function __tostring

End of class Name.

Class Value: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
127.87 ms | 1452 KiB | 15 Q