3v4l.org

run code in 300+ PHP versions simultaneously
<?php # http://scribu.net/blog/defaultdict-in-php.html class Defaultdict implements ArrayAccess { private $container = array(); private $default; public function __construct( $default ) { $this->default = $default; } public function offsetSet( $offset, $value ) { if ( is_null($offset) ) { trigger_error( sprintf( "Trying to use %s as a list.", __CLASS__ ), E_USER_WARNING ); return; } $this->container[$offset] = $value; } public function offsetExists( $offset ) { return true; } public function offsetUnset( $offset ) { unset( $this->container[$offset] ); } public function &offsetGet( $offset ) { if ( !isset( $this->container[$offset] ) ) { if ( is_callable($this->default) ) $value = call_user_func( $this->default, $offset ); else $value = $this->default; $this->container[$offset] = $value; } return $this->container[$offset]; } } $counts = new Defaultdict(1); $counts['English']++; print_r(array_keys($counts));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nkm4c
function name:  (null)
number of ops:  14
compiled vars:  !0 = $counts
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CLASS                                            'defaultdict'
   33     1        NEW                                              $1      'Defaultdict'
          2        SEND_VAL_EX                                              1
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   34     5        FETCH_DIM_RW                                     $4      !0, 'English'
          6        PRE_INC                                                  $4
   35     7        INIT_FCALL                                               'print_r'
          8        INIT_FCALL                                               'array_keys'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $6      
         11        SEND_VAR                                                 $6
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

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

End of function __construct

Function offsetset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nkm4c
function name:  offsetSet
number of ops:  17
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   10     2        TYPE_CHECK                                    2          !0
          3      > JMPZ                                                     ~2, ->13
   11     4    >   INIT_FCALL                                               'trigger_error'
          5        INIT_FCALL                                               'sprintf'
          6        SEND_VAL                                                 'Trying+to+use+%25s+as+a+list.'
          7        SEND_VAL                                                 'Defaultdict'
          8        DO_ICALL                                         $3      
          9        SEND_VAR                                                 $3
         10        SEND_VAL                                                 512
         11        DO_ICALL                                                 
   12    12      > RETURN                                                   null
   14    13    >   FETCH_OBJ_W                                      $5      'container'
         14        ASSIGN_DIM                                               $5, !0
         15        OP_DATA                                                  !1
   15    16      > RETURN                                                   null

End of function offsetset

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nkm4c
function name:  offsetExists
number of ops:  3
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1      > RETURN                                                   <true>
   18     2*     > RETURN                                                   null

End of function offsetexists

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nkm4c
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        FETCH_OBJ_UNSET                                  $1      'container'
          2        UNSET_DIM                                                $1, !0
   21     3      > RETURN                                                   null

End of function offsetunset

Function offsetget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 21
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Return found
Branch analysis from position: 16
Return found
Branch analysis from position: 21
filename:       /in/nkm4c
function name:  offsetGet
number of ops:  25
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   23     1        FETCH_OBJ_IS                                     ~2      'container'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~3      ~2, !0
          3        BOOL_NOT                                         ~4      ~3
          4      > JMPZ                                                     ~4, ->21
   24     5    >   INIT_FCALL                                               'is_callable'
          6        FETCH_OBJ_R                                      ~5      'default'
          7        SEND_VAL                                                 ~5
          8        DO_ICALL                                         $6      
          9      > JMPZ                                                     $6, ->16
   25    10    >   FETCH_OBJ_R                                      ~7      'default'
         11        INIT_USER_CALL                                1          'call_user_func', ~7
         12        SEND_USER                                                !0
         13        DO_FCALL                                      0  $8      
         14        ASSIGN                                                   !1, $8
   24    15      > JMP                                                      ->18
   27    16    >   FETCH_OBJ_R                                      ~10     'default'
         17        ASSIGN                                                   !1, ~10
   28    18    >   FETCH_OBJ_W                                      $12     'container'
         19        ASSIGN_DIM                                               $12, !0
         20        OP_DATA                                                  !1
   30    21    >   FETCH_OBJ_W                                      $14     'container'
         22        FETCH_DIM_W                                      $15     $14, !0
         23      > RETURN_BY_REF                                            $15
   31    24*     > RETURN_BY_REF                                            null

End of function offsetget

End of class Defaultdict.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.6 ms | 1472 KiB | 18 Q