3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Image { public function __construct($path) { $this->image = imagecreatefromjpeg($path); } public function getSize() { return array(imagesx($this->image), imagesy($this->image)); } } class ImageProxy extends Image { protected $image; public function __construct($path) { $this->path = $path; } private function init() { if ( ! $this->image) { $this->image = new Image($this->path); } } public function getSize() { $this->init(); return $this->image->getSize(); } } $img1 = new ImageProxy('/path/to/image1.jpg'); var_dump(memory_get_usage()); // ~200Kb $img2 = new ImageProxy('/path/to/image2.jpg'); var_dump(memory_get_usage()); // ~200Kb $img3 = new ImageProxy('/path/to/image3.jpg'); var_dump(memory_get_usage()); // ~200Kb $size1 = $img1->getSize(); var_dump(memory_get_usage()); // ~4Mb $size2 = $img2->getSize(); var_dump(memory_get_usage()); // ~8Mb
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B0EXt
function name:  (null)
number of ops:  44
compiled vars:  !0 = $img1, !1 = $img2, !2 = $img3, !3 = $size1, !4 = $size2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   NEW                                              $5      'ImageProxy'
          1        SEND_VAL_EX                                              '%2Fpath%2Fto%2Fimage1.jpg'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $5
   32     4        INIT_FCALL                                               'var_dump'
          5        INIT_FCALL                                               'memory_get_usage'
          6        DO_ICALL                                         $8      
          7        SEND_VAR                                                 $8
          8        DO_ICALL                                                 
   33     9        NEW                                              $10     'ImageProxy'
         10        SEND_VAL_EX                                              '%2Fpath%2Fto%2Fimage2.jpg'
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !1, $10
   34    13        INIT_FCALL                                               'var_dump'
         14        INIT_FCALL                                               'memory_get_usage'
         15        DO_ICALL                                         $13     
         16        SEND_VAR                                                 $13
         17        DO_ICALL                                                 
   35    18        NEW                                              $15     'ImageProxy'
         19        SEND_VAL_EX                                              '%2Fpath%2Fto%2Fimage3.jpg'
         20        DO_FCALL                                      0          
         21        ASSIGN                                                   !2, $15
   36    22        INIT_FCALL                                               'var_dump'
         23        INIT_FCALL                                               'memory_get_usage'
         24        DO_ICALL                                         $18     
         25        SEND_VAR                                                 $18
         26        DO_ICALL                                                 
   38    27        INIT_METHOD_CALL                                         !0, 'getSize'
         28        DO_FCALL                                      0  $20     
         29        ASSIGN                                                   !3, $20
   39    30        INIT_FCALL                                               'var_dump'
         31        INIT_FCALL                                               'memory_get_usage'
         32        DO_ICALL                                         $22     
         33        SEND_VAR                                                 $22
         34        DO_ICALL                                                 
   40    35        INIT_METHOD_CALL                                         !1, 'getSize'
         36        DO_FCALL                                      0  $24     
         37        ASSIGN                                                   !4, $24
   41    38        INIT_FCALL                                               'var_dump'
         39        INIT_FCALL                                               'memory_get_usage'
         40        DO_ICALL                                         $26     
         41        SEND_VAR                                                 $26
         42        DO_ICALL                                                 
         43      > RETURN                                                   1

Class Image:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B0EXt
function name:  __construct
number of ops:  7
compiled vars:  !0 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        INIT_FCALL_BY_NAME                                       'imagecreatefromjpeg'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $2      
          4        ASSIGN_OBJ                                               'image'
          5        OP_DATA                                                  $2
    6     6      > RETURN                                                   null

End of function __construct

Function getsize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B0EXt
function name:  getSize
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   INIT_FCALL_BY_NAME                                       'imagesx'
          1        CHECK_FUNC_ARG                                           
          2        FETCH_OBJ_FUNC_ARG                               $0      'image'
          3        SEND_FUNC_ARG                                            $0
          4        DO_FCALL                                      0  $1      
          5        INIT_ARRAY                                       ~2      $1
          6        INIT_FCALL_BY_NAME                                       'imagesy'
          7        CHECK_FUNC_ARG                                           
          8        FETCH_OBJ_FUNC_ARG                               $3      'image'
          9        SEND_FUNC_ARG                                            $3
         10        DO_FCALL                                      0  $4      
         11        ADD_ARRAY_ELEMENT                                ~2      $4
         12      > RETURN                                                   ~2
   10    13*     > RETURN                                                   null

End of function getsize

End of class Image.

Class ImageProxy:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B0EXt
function name:  __construct
number of ops:  4
compiled vars:  !0 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
   16     1        ASSIGN_OBJ                                               'path'
          2        OP_DATA                                                  !0
   17     3      > RETURN                                                   null

End of function __construct

Function init:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/B0EXt
function name:  init
number of ops:  11
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_OBJ_R                                      ~0      'image'
          1        BOOL_NOT                                         ~1      ~0
          2      > JMPZ                                                     ~1, ->10
   21     3    >   NEW                                              $3      'Image'
          4        CHECK_FUNC_ARG                                           
          5        FETCH_OBJ_FUNC_ARG                               $4      'path'
          6        SEND_FUNC_ARG                                            $4
          7        DO_FCALL                                      0          
          8        ASSIGN_OBJ                                               'image'
          9        OP_DATA                                                  $3
   23    10    > > RETURN                                                   null

End of function init

Function getsize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B0EXt
function name:  getSize
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_METHOD_CALL                                         'init'
          1        DO_FCALL                                      0          
   27     2        FETCH_OBJ_R                                      ~1      'image'
          3        INIT_METHOD_CALL                                         ~1, 'getSize'
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   28     6*     > RETURN                                                   null

End of function getsize

End of class ImageProxy.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.17 ms | 1396 KiB | 17 Q