3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Leak { static protected function &leaked(array &$array = null) { $array = array('one'); return $array; } public function toLeaked($array = null) { $array = static::leaked($array); return $array; } public function testLeak() { echo "memory before loop: " . memory_get_usage(true) . PHP_EOL; for ($i = 0; $i < 20000; $i++) { $leak = $this->toLeaked(); } gc_collect_cycles(); echo "memory after loop: " . memory_get_usage(true) . PHP_EOL; } } $leak = new Leak(); $leak->testLeak();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XBPgY
function name:  (null)
number of ops:  6
compiled vars:  !0 = $leak
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   24     0  E >   NEW                                                  $1      'Leak'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $1
   25     3        INIT_METHOD_CALL                                             !0, 'testLeak'
          4        DO_FCALL                                          0          
          5      > RETURN                                                       1

Class Leak:
Function leaked:
Finding entry points
Branch analysis from position: 0
Return found
filename:       /in/XBPgY
function name:  leaked
number of ops:  4
compiled vars:  !0 = $array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV_INIT                                            !0      null
    5     1        ASSIGN                                                       !0, <array>
    6     2      > RETURN_BY_REF                                                !0
    7     3*     > RETURN_BY_REF                                                null

End of function leaked

Function toleaked:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XBPgY
function name:  toLeaked
number of ops:  7
compiled vars:  !0 = $array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV_INIT                                            !0      null
   10     1        INIT_STATIC_METHOD_CALL                                      'leaked'
          2        SEND_VAR_EX                                                  !0
          3        DO_FCALL                                          0  $1      
          4        ASSIGN                                                       !0, $1
   11     5      > RETURN                                                       !0
   12     6*     > RETURN                                                       null

End of function toleaked

Function testleak:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 8
Branch analysis from position: 14
Branch analysis from position: 8
filename:       /in/XBPgY
function name:  testLeak
number of ops:  23
compiled vars:  !0 = $i, !1 = $leak
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                                   'memory_get_usage'
          1        SEND_VAL                                                     <true>
          2        DO_ICALL                                             $2      
          3        CONCAT                                               ~3      'memory+before+loop%3A+', $2
          4        CONCAT                                               ~4      ~3, '%0A'
          5        ECHO                                                         ~4
   16     6        ASSIGN                                                       !0, 0
          7      > JMP                                                          ->12
   17     8    >   INIT_METHOD_CALL                                             'toLeaked'
          9        DO_FCALL                                          0  $6      
         10        ASSIGN                                                       !1, $6
   16    11        PRE_INC                                                      !0
         12    >   IS_SMALLER                                                   !0, 20000
         13      > JMPNZ                                                        ~9, ->8
   19    14    >   INIT_FCALL                                                   'gc_collect_cycles'
         15        DO_ICALL                                                     
   20    16        INIT_FCALL                                                   'memory_get_usage'
         17        SEND_VAL                                                     <true>
         18        DO_ICALL                                             $11     
         19        CONCAT                                               ~12     'memory+after+loop%3A+', $11
         20        CONCAT                                               ~13     ~12, '%0A'
         21        ECHO                                                         ~13
   21    22      > RETURN                                                       null

End of function testleak

End of class Leak.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.88 ms | 1184 KiB | 15 Q