3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Model { protected $comments; public function __construct() { $this->comments = new class { public function count() { return rand(1, 20); } }; } } class Post extends Model { public function commentCount() { static $cache; return $cache?: $cache = $this->comments->count(); } } $post = new Post(); var_dump($post->commentCount()); var_dump($post->commentCount()); var_dump($post->commentCount()); var_dump($post->commentCount()); var_dump($post->commentCount());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlXpC
function name:  (null)
number of ops:  29
compiled vars:  !0 = $post
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   NEW                                              $1      'Post'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   30     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'commentCount'
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
   31     8        INIT_FCALL                                               'var_dump'
          9        INIT_METHOD_CALL                                         !0, 'commentCount'
         10        DO_FCALL                                      0  $6      
         11        SEND_VAR                                                 $6
         12        DO_ICALL                                                 
   32    13        INIT_FCALL                                               'var_dump'
         14        INIT_METHOD_CALL                                         !0, 'commentCount'
         15        DO_FCALL                                      0  $8      
         16        SEND_VAR                                                 $8
         17        DO_ICALL                                                 
   33    18        INIT_FCALL                                               'var_dump'
         19        INIT_METHOD_CALL                                         !0, 'commentCount'
         20        DO_FCALL                                      0  $10     
         21        SEND_VAR                                                 $10
         22        DO_ICALL                                                 
   34    23        INIT_FCALL                                               'var_dump'
         24        INIT_METHOD_CALL                                         !0, 'commentCount'
         25        DO_FCALL                                      0  $12     
         26        SEND_VAR                                                 $12
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Class class@anonymous:
Function count:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlXpC
function name:  count
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   INIT_FCALL                                               'rand'
          1        SEND_VAL                                                 1
          2        SEND_VAL                                                 20
          3        DO_ICALL                                         $0      
          4      > RETURN                                                   $0
   13     5*     > RETURN                                                   null

End of function count

End of class class@anonymous.

Class Model:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlXpC
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   DECLARE_ANON_CLASS                               <unknown> 
          1        NEW                                              $2      $1
          2        DO_FCALL                                      0          
          3        ASSIGN_OBJ                                               'comments'
          4        OP_DATA                                                  $2
   15     5      > RETURN                                                   null

End of function __construct

End of class Model.

Class Post:
Function commentcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlXpC
function name:  commentCount
number of ops:  9
compiled vars:  !0 = $cache
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   BIND_STATIC                                              !0
   24     1        JMP_SET                                          ~1      !0, ->7
          2        FETCH_OBJ_R                                      ~2      'comments'
          3        INIT_METHOD_CALL                                         ~2, 'count'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                           ~4      !0, $3
          6        QM_ASSIGN                                        ~1      ~4
          7      > RETURN                                                   ~1
   25     8*     > RETURN                                                   null

End of function commentcount

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FlXpC
function name:  __construct
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   DECLARE_ANON_CLASS                               <unknown> 
          1        NEW                                              $2      $1
          2        DO_FCALL                                      0          
          3        ASSIGN_OBJ                                               'comments'
          4        OP_DATA                                                  $2
   15     5      > RETURN                                                   null

End of function __construct

End of class Post.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.99 ms | 1400 KiB | 17 Q