3v4l.org

run code in 300+ PHP versions simultaneously
<?php class a{ function __construct(){ echo 'class a __construct'."\n"; } function a1(){ echo 'a1'."\n"; } function a2(){ echo 'a2'."\n"; } function a3(){ echo 'a3'."\n"; } } class b{ protected $cache; function __construct(){ echo 'class b __construct'."\n"; } function b1($tags='tags'){ return new a(); } function b2($tags='tags'){ static $cache=[]; if(isset($cache[$tags])) return $cache[$tags]; return $cache[$tags]=new a(); } function b3($tags='tags'){ if(isset($this->cache[$tags])) return $this->cache[$tags]; return $this->cache[$tags]=new a(); } } /*内存计算*/ $start = memory_get_usage(); $b=new b(); $b->b1()->a1(); $b->b1()->a2(); $b->b1()->a3(); /*内存计算*/ $end = memory_get_usage(); echo '内存'.($end-$start)."\n"; /*内存计算*/ $start = memory_get_usage(); $b=new b(); $b->b2()->a1(); $b->b2()->a2(); $b->b2()->a3(); /*内存计算*/ $end = memory_get_usage(); echo '内存'.($end-$start)."\n"; /*内存计算*/ $start = memory_get_usage(); $b=new b(); $b->b3()->a1(); $b->b3()->a2(); $b->b3()->a3(); /*内存计算*/ $end = memory_get_usage(); echo '内存'.($end-$start)."\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0sU7o
function name:  (null)
number of ops:  76
compiled vars:  !0 = $start, !1 = $b, !2 = $end
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   INIT_FCALL                                               'memory_get_usage'
          1        DO_ICALL                                         $3      
          2        ASSIGN                                                   !0, $3
   46     3        NEW                                              $5      'b'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   47     6        INIT_METHOD_CALL                                         !1, 'b1'
          7        DO_FCALL                                      0  $8      
          8        INIT_METHOD_CALL                                         $8, 'a1'
          9        DO_FCALL                                      0          
   48    10        INIT_METHOD_CALL                                         !1, 'b1'
         11        DO_FCALL                                      0  $10     
         12        INIT_METHOD_CALL                                         $10, 'a2'
         13        DO_FCALL                                      0          
   49    14        INIT_METHOD_CALL                                         !1, 'b1'
         15        DO_FCALL                                      0  $12     
         16        INIT_METHOD_CALL                                         $12, 'a3'
         17        DO_FCALL                                      0          
   51    18        INIT_FCALL                                               'memory_get_usage'
         19        DO_ICALL                                         $14     
         20        ASSIGN                                                   !2, $14
   52    21        SUB                                              ~16     !2, !0
         22        CONCAT                                           ~17     '%E5%86%85%E5%AD%98', ~16
         23        CONCAT                                           ~18     ~17, '%0A'
         24        ECHO                                                     ~18
   55    25        INIT_FCALL                                               'memory_get_usage'
         26        DO_ICALL                                         $19     
         27        ASSIGN                                                   !0, $19
   56    28        NEW                                              $21     'b'
         29        DO_FCALL                                      0          
         30        ASSIGN                                                   !1, $21
   57    31        INIT_METHOD_CALL                                         !1, 'b2'
         32        DO_FCALL                                      0  $24     
         33        INIT_METHOD_CALL                                         $24, 'a1'
         34        DO_FCALL                                      0          
   58    35        INIT_METHOD_CALL                                         !1, 'b2'
         36        DO_FCALL                                      0  $26     
         37        INIT_METHOD_CALL                                         $26, 'a2'
         38        DO_FCALL                                      0          
   59    39        INIT_METHOD_CALL                                         !1, 'b2'
         40        DO_FCALL                                      0  $28     
         41        INIT_METHOD_CALL                                         $28, 'a3'
         42        DO_FCALL                                      0          
   61    43        INIT_FCALL                                               'memory_get_usage'
         44        DO_ICALL                                         $30     
         45        ASSIGN                                                   !2, $30
   62    46        SUB                                              ~32     !2, !0
         47        CONCAT                                           ~33     '%E5%86%85%E5%AD%98', ~32
         48        CONCAT                                           ~34     ~33, '%0A'
         49        ECHO                                                     ~34
   65    50        INIT_FCALL                                               'memory_get_usage'
         51        DO_ICALL                                         $35     
         52        ASSIGN                                                   !0, $35
   66    53        NEW                                              $37     'b'
         54        DO_FCALL                                      0          
         55        ASSIGN                                                   !1, $37
   67    56        INIT_METHOD_CALL                                         !1, 'b3'
         57        DO_FCALL                                      0  $40     
         58        INIT_METHOD_CALL                                         $40, 'a1'
         59        DO_FCALL                                      0          
   68    60        INIT_METHOD_CALL                                         !1, 'b3'
         61        DO_FCALL                                      0  $42     
         62        INIT_METHOD_CALL                                         $42, 'a2'
         63        DO_FCALL                                      0          
   69    64        INIT_METHOD_CALL                                         !1, 'b3'
         65        DO_FCALL                                      0  $44     
         66        INIT_METHOD_CALL                                         $44, 'a3'
         67        DO_FCALL                                      0          
   71    68        INIT_FCALL                                               'memory_get_usage'
         69        DO_ICALL                                         $46     
         70        ASSIGN                                                   !2, $46
   72    71        SUB                                              ~48     !2, !0
         72        CONCAT                                           ~49     '%E5%86%85%E5%AD%98', ~48
         73        CONCAT                                           ~50     ~49, '%0A'
         74        ECHO                                                     ~50
         75      > RETURN                                                   1

Class a:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0sU7o
function name:  __construct
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   ECHO                                                     'class+a+__construct%0A'
    6     1      > RETURN                                                   null

End of function __construct

Function a1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0sU7o
function name:  a1
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   ECHO                                                     'a1%0A'
   10     1      > RETURN                                                   null

End of function a1

Function a2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0sU7o
function name:  a2
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ECHO                                                     'a2%0A'
   14     1      > RETURN                                                   null

End of function a2

Function a3:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0sU7o
function name:  a3
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ECHO                                                     'a3%0A'
   18     1      > RETURN                                                   null

End of function a3

End of class a.

Class b:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0sU7o
function name:  __construct
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ECHO                                                     'class+b+__construct%0A'
   26     1      > RETURN                                                   null

End of function __construct

Function b1:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0sU7o
function name:  b1
number of ops:  5
compiled vars:  !0 = $tags
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV_INIT                                        !0      'tags'
   29     1        NEW                                              $1      'a'
          2        DO_FCALL                                      0          
          3      > RETURN                                                   $1
   30     4*     > RETURN                                                   null

End of function b1

Function b2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0sU7o
function name:  b2
number of ops:  12
compiled vars:  !0 = $tags, !1 = $cache
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV_INIT                                        !0      'tags'
   33     1        BIND_STATIC                                              !1
   34     2        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !0
          3      > JMPZ                                                     ~2, ->6
          4    >   FETCH_DIM_R                                      ~3      !1, !0
          5      > RETURN                                                   ~3
   35     6    >   NEW                                              $5      'a'
          7        DO_FCALL                                      0          
          8        ASSIGN_DIM                                       ~4      !1, !0
          9        OP_DATA                                                  $5
         10      > RETURN                                                   ~4
   36    11*     > RETURN                                                   null

End of function b2

Function b3:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0sU7o
function name:  b3
number of ops:  14
compiled vars:  !0 = $tags
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   RECV_INIT                                        !0      'tags'
   39     1        FETCH_OBJ_IS                                     ~1      'cache'
          2        ISSET_ISEMPTY_DIM_OBJ                         0          ~1, !0
          3      > JMPZ                                                     ~2, ->7
          4    >   FETCH_OBJ_R                                      ~3      'cache'
          5        FETCH_DIM_R                                      ~4      ~3, !0
          6      > RETURN                                                   ~4
   40     7    >   NEW                                              $7      'a'
          8        DO_FCALL                                      0          
          9        FETCH_OBJ_W                                      $5      'cache'
         10        ASSIGN_DIM                                       ~6      $5, !0
         11        OP_DATA                                                  $7
         12      > RETURN                                                   ~6
   41    13*     > RETURN                                                   null

End of function b3

End of class b.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.4 ms | 1408 KiB | 15 Q