3v4l.org

run code in 300+ 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() . PHP_EOL; for ($i = 0; $i < 20000; $i++) { $leak = $this->toLeaked(); } gc_collect_cycles(); echo "memory after loop: " . memory_get_usage() . 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/dntLu
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/dntLu
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/dntLu
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 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 7
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 7
Branch analysis from position: 13
Branch analysis from position: 7
filename:       /in/dntLu
function name:  testLeak
number of ops:  21
compiled vars:  !0 = $i, !1 = $leak
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   INIT_FCALL                                               'memory_get_usage'
          1        DO_ICALL                                         $2      
          2        CONCAT                                           ~3      'memory+before+loop%3A+', $2
          3        CONCAT                                           ~4      ~3, '%0A'
          4        ECHO                                                     ~4
   16     5        ASSIGN                                                   !0, 0
          6      > JMP                                                      ->11
   17     7    >   INIT_METHOD_CALL                                         'toLeaked'
          8        DO_FCALL                                      0  $6      
          9        ASSIGN                                                   !1, $6
   16    10        PRE_INC                                                  !0
         11    >   IS_SMALLER                                               !0, 20000
         12      > JMPNZ                                                    ~9, ->7
   19    13    >   INIT_FCALL                                               'gc_collect_cycles'
         14        DO_ICALL                                                 
   20    15        INIT_FCALL                                               'memory_get_usage'
         16        DO_ICALL                                         $11     
         17        CONCAT                                           ~12     'memory+after+loop%3A+', $11
         18        CONCAT                                           ~13     ~12, '%0A'
         19        ECHO                                                     ~13
   21    20      > RETURN                                                   null

End of function testleak

End of class Leak.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
132.49 ms | 1405 KiB | 17 Q