3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Memory leak somewhere around __set? class A { var $data = array(); function __get($k) { return $this->data[$k]; } function __set($k, $v) { return $this->data[$k] = $v; } } $b = new A(); for ($i = 0; $i < 500000; $i++) $b->{"a$i"} = 'abc'; var_dump(memory_get_usage()); // int(78318488) - why so big? $c = clone $b; unset($b); var_dump(memory_get_usage()); // int(42220972) - OK unset($c); $b = new A(); for ($i = 0; $i < 500000; $i++) $b->__set("a$i", 'abc'); var_dump(memory_get_usage()); // int(42221492) - OK

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 5
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 31
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 31
Branch analysis from position: 40
Branch analysis from position: 31
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 5
Branch analysis from position: 12
Branch analysis from position: 5
filename:       /in/l4e7n
function name:  (null)
number of ops:  46
compiled vars:  !0 = $b, !1 = $i, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   NEW                                              $3      'A'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   20     3        ASSIGN                                                   !1, 0
          4      > JMP                                                      ->10
   21     5    >   NOP                                                      
          6        FAST_CONCAT                                      ~7      'a', !1
          7        ASSIGN_OBJ                                               !0, ~7
          8        OP_DATA                                                  'abc'
   20     9        PRE_INC                                                  !1
         10    >   IS_SMALLER                                               !1, 500000
         11      > JMPNZ                                                    ~10, ->5
   22    12    >   INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'memory_get_usage'
         14        DO_ICALL                                         $11     
         15        SEND_VAR                                                 $11
         16        DO_ICALL                                                 
   23    17        CLONE                                            ~13     !0
         18        ASSIGN                                                   !2, ~13
   24    19        UNSET_CV                                                 !0
   25    20        INIT_FCALL                                               'var_dump'
         21        INIT_FCALL                                               'memory_get_usage'
         22        DO_ICALL                                         $15     
         23        SEND_VAR                                                 $15
         24        DO_ICALL                                                 
   27    25        UNSET_CV                                                 !2
   28    26        NEW                                              $17     'A'
         27        DO_FCALL                                      0          
         28        ASSIGN                                                   !0, $17
   29    29        ASSIGN                                                   !1, 0
         30      > JMP                                                      ->38
   30    31    >   INIT_METHOD_CALL                                         !0, '__set'
         32        NOP                                                      
         33        FAST_CONCAT                                      ~21     'a', !1
         34        SEND_VAL_EX                                              ~21
         35        SEND_VAL_EX                                              'abc'
         36        DO_FCALL                                      0          
   29    37        PRE_INC                                                  !1
         38    >   IS_SMALLER                                               !1, 500000
         39      > JMPNZ                                                    ~24, ->31
   31    40    >   INIT_FCALL                                               'var_dump'
         41        INIT_FCALL                                               'memory_get_usage'
         42        DO_ICALL                                         $25     
         43        SEND_VAR                                                 $25
         44        DO_ICALL                                                 
         45      > RETURN                                                   1

Class A:
Function __get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l4e7n
function name:  __get
number of ops:  5
compiled vars:  !0 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        FETCH_OBJ_R                                      ~1      'data'
          2        FETCH_DIM_R                                      ~2      ~1, !0
          3      > RETURN                                                   ~2
   11     4*     > RETURN                                                   null

End of function __get

Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l4e7n
function name:  __set
number of ops:  7
compiled vars:  !0 = $k, !1 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        FETCH_OBJ_W                                      $2      'data'
          3        ASSIGN_DIM                                       ~3      $2, !0
          4        OP_DATA                                                  !1
          5      > RETURN                                                   ~3
   15     6*     > RETURN                                                   null

End of function __set

End of class A.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.43 ms | 1400 KiB | 17 Q