3v4l.org

run code in 300+ PHP versions simultaneously
<?php class VarStorage { protected $_property; public function setProperty($value) { $this->_property = $value; } public function getProperty() { return $this->_property; } } function mem_print($message, $before, $after) { $difference = ($after - $before) / 1000000; echo sprintf($message, sprintf('%.2fM', $difference)); echo "\n"; } echo "Testing class in a PHP script\n\n"; // Create massive variable $mBeforeA = memory_get_usage(); $a1 = str_repeat('a', 3000000); $mAfterA = memory_get_usage(); mem_print('Creating $a1: %s', $mBeforeA, $mAfterA); // Refcount increases $a2 = str_repeat('a', 3000000); $mBeforeB = memory_get_usage(); $b = $a2; $mAfterB = memory_get_usage(); mem_print('$b = $a2: %s', $mBeforeB, $mAfterB); // Separation $mBeforeSeparation = memory_get_usage(); $b .= 'data'; $mAfterSeparation = memory_get_usage(); mem_print('$b .= \'data\': %s', $mBeforeSeparation, $mAfterSeparation); // Setting to a class property $a4 = str_repeat('a', 3000000); $class = new VarStorage; $mBeforeStorageSet = memory_get_usage(); $class->setProperty($a4); $mAfterStorageSet = memory_get_usage(); mem_print('$class->setProperty($a4): %s', $mBeforeStorageSet, $mAfterStorageSet); // Getting from a class property $mBeforeStorageGet = memory_get_usage(); $result = $class->getProperty(); $mAfterStorageGet = memory_get_usage(); mem_print('$result = $class->getProperty(): %s', $mBeforeStorageGet, $mAfterStorageGet); $mBeforeSeparationFromStorage = memory_get_usage(); $result .= 'data'; $mAfterSeparationFromStorage = memory_get_usage(); mem_print('$result .= \'data\': %s', $mBeforeSeparationFromStorage, $mAfterSeparationFromStorage);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/94oXF
function name:  (null)
number of ops:  95
compiled vars:  !0 = $mBeforeA, !1 = $a1, !2 = $mAfterA, !3 = $a2, !4 = $mBeforeB, !5 = $b, !6 = $mAfterB, !7 = $mBeforeSeparation, !8 = $mAfterSeparation, !9 = $a4, !10 = $class, !11 = $mBeforeStorageSet, !12 = $mAfterStorageSet, !13 = $mBeforeStorageGet, !14 = $result, !15 = $mAfterStorageGet, !16 = $mBeforeSeparationFromStorage, !17 = $mAfterSeparationFromStorage
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ECHO                                                     'Testing+class+in+a+PHP+script%0A%0A'
   26     1        INIT_FCALL                                               'memory_get_usage'
          2        DO_ICALL                                         $18     
          3        ASSIGN                                                   !0, $18
   27     4        INIT_FCALL                                               'str_repeat'
          5        SEND_VAL                                                 'a'
          6        SEND_VAL                                                 3000000
          7        DO_ICALL                                         $20     
          8        ASSIGN                                                   !1, $20
   28     9        INIT_FCALL                                               'memory_get_usage'
         10        DO_ICALL                                         $22     
         11        ASSIGN                                                   !2, $22
   29    12        INIT_FCALL                                               'mem_print'
         13        SEND_VAL                                                 'Creating+%24a1%3A+%25s'
         14        SEND_VAR                                                 !0
         15        SEND_VAR                                                 !2
         16        DO_FCALL                                      0          
   32    17        INIT_FCALL                                               'str_repeat'
         18        SEND_VAL                                                 'a'
         19        SEND_VAL                                                 3000000
         20        DO_ICALL                                         $25     
         21        ASSIGN                                                   !3, $25
   33    22        INIT_FCALL                                               'memory_get_usage'
         23        DO_ICALL                                         $27     
         24        ASSIGN                                                   !4, $27
   34    25        ASSIGN                                                   !5, !3
   35    26        INIT_FCALL                                               'memory_get_usage'
         27        DO_ICALL                                         $30     
         28        ASSIGN                                                   !6, $30
   36    29        INIT_FCALL                                               'mem_print'
         30        SEND_VAL                                                 '%24b+%3D+%24a2%3A+%25s'
         31        SEND_VAR                                                 !4
         32        SEND_VAR                                                 !6
         33        DO_FCALL                                      0          
   39    34        INIT_FCALL                                               'memory_get_usage'
         35        DO_ICALL                                         $33     
         36        ASSIGN                                                   !7, $33
   40    37        ASSIGN_OP                                     8          !5, 'data'
   41    38        INIT_FCALL                                               'memory_get_usage'
         39        DO_ICALL                                         $36     
         40        ASSIGN                                                   !8, $36
   42    41        INIT_FCALL                                               'mem_print'
         42        SEND_VAL                                                 '%24b+.%3D+%27data%27%3A+%25s'
         43        SEND_VAR                                                 !7
         44        SEND_VAR                                                 !8
         45        DO_FCALL                                      0          
   45    46        INIT_FCALL                                               'str_repeat'
         47        SEND_VAL                                                 'a'
         48        SEND_VAL                                                 3000000
         49        DO_ICALL                                         $39     
         50        ASSIGN                                                   !9, $39
   46    51        NEW                                              $41     'VarStorage'
         52        DO_FCALL                                      0          
         53        ASSIGN                                                   !10, $41
   47    54        INIT_FCALL                                               'memory_get_usage'
         55        DO_ICALL                                         $44     
         56        ASSIGN                                                   !11, $44
   48    57        INIT_METHOD_CALL                                         !10, 'setProperty'
         58        SEND_VAR_EX                                              !9
         59        DO_FCALL                                      0          
   49    60        INIT_FCALL                                               'memory_get_usage'
         61        DO_ICALL                                         $47     
         62        ASSIGN                                                   !12, $47
   50    63        INIT_FCALL                                               'mem_print'
         64        SEND_VAL                                                 '%24class-%3EsetProperty%28%24a4%29%3A+%25s'
         65        SEND_VAR                                                 !11
         66        SEND_VAR                                                 !12
         67        DO_FCALL                                      0          
   53    68        INIT_FCALL                                               'memory_get_usage'
         69        DO_ICALL                                         $50     
         70        ASSIGN                                                   !13, $50
   54    71        INIT_METHOD_CALL                                         !10, 'getProperty'
         72        DO_FCALL                                      0  $52     
         73        ASSIGN                                                   !14, $52
   55    74        INIT_FCALL                                               'memory_get_usage'
         75        DO_ICALL                                         $54     
         76        ASSIGN                                                   !15, $54
   56    77        INIT_FCALL                                               'mem_print'
         78        SEND_VAL                                                 '%24result+%3D+%24class-%3EgetProperty%28%29%3A+%25s'
         79        SEND_VAR                                                 !13
         80        SEND_VAR                                                 !15
         81        DO_FCALL                                      0          
   58    82        INIT_FCALL                                               'memory_get_usage'
         83        DO_ICALL                                         $57     
         84        ASSIGN                                                   !16, $57
   59    85        ASSIGN_OP                                     8          !14, 'data'
   60    86        INIT_FCALL                                               'memory_get_usage'
         87        DO_ICALL                                         $60     
         88        ASSIGN                                                   !17, $60
   61    89        INIT_FCALL                                               'mem_print'
         90        SEND_VAL                                                 '%24result+.%3D+%27data%27%3A+%25s'
         91        SEND_VAR                                                 !16
         92        SEND_VAR                                                 !17
         93        DO_FCALL                                      0          
         94      > RETURN                                                   1

Function mem_print:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/94oXF
function name:  mem_print
number of ops:  17
compiled vars:  !0 = $message, !1 = $before, !2 = $after, !3 = $difference
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   18     3        SUB                                              ~4      !2, !1
          4        DIV                                              ~5      ~4, 1000000
          5        ASSIGN                                                   !3, ~5
   19     6        INIT_FCALL                                               'sprintf'
          7        SEND_VAR                                                 !0
          8        INIT_FCALL                                               'sprintf'
          9        SEND_VAL                                                 '%25.2fM'
         10        SEND_VAR                                                 !3
         11        DO_ICALL                                         $7      
         12        SEND_VAR                                                 $7
         13        DO_ICALL                                         $8      
         14        ECHO                                                     $8
   20    15        ECHO                                                     '%0A'
   21    16      > RETURN                                                   null

End of function mem_print

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

End of function setproperty

Function getproperty:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/94oXF
function name:  getProperty
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   FETCH_OBJ_R                                      ~0      '_property'
          1      > RETURN                                                   ~0
   14     2*     > RETURN                                                   null

End of function getproperty

End of class VarStorage.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.08 ms | 1407 KiB | 25 Q