3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Model { protected $comments; public function __construct() { $this->comments = new class { public function count() { $responses = [ 1, 2, 3, "Error: could not connect to database", 5 ]; $rand = rand(0, 4); if (is_string($responses[$rand])) { throw new Exception($responses[$rand]); } return $responses[$rand]; } }; } } 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/Yfmub
function name:  (null)
number of ops:  29
compiled vars:  !0 = $post
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   NEW                                              $1      'Post'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   44     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'commentCount'
          5        DO_FCALL                                      0  $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
   45     8        INIT_FCALL                                               'var_dump'
          9        INIT_METHOD_CALL                                         !0, 'commentCount'
         10        DO_FCALL                                      0  $6      
         11        SEND_VAR                                                 $6
         12        DO_ICALL                                                 
   46    13        INIT_FCALL                                               'var_dump'
         14        INIT_METHOD_CALL                                         !0, 'commentCount'
         15        DO_FCALL                                      0  $8      
         16        SEND_VAR                                                 $8
         17        DO_ICALL                                                 
   47    18        INIT_FCALL                                               'var_dump'
         19        INIT_METHOD_CALL                                         !0, 'commentCount'
         20        DO_FCALL                                      0  $10     
         21        SEND_VAR                                                 $10
         22        DO_ICALL                                                 
   48    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
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Yfmub
function name:  count
number of ops:  18
compiled vars:  !0 = $responses, !1 = $rand
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                   !0, <array>
   20     1        INIT_FCALL                                               'rand'
          2        SEND_VAL                                                 0
          3        SEND_VAL                                                 4
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !1, $3
   22     6        FETCH_DIM_R                                      ~5      !0, !1
          7        TYPE_CHECK                                   64          ~5
          8      > JMPZ                                                     ~6, ->15
   23     9    >   NEW                                              $7      'Exception'
         10        CHECK_FUNC_ARG                                           
         11        FETCH_DIM_FUNC_ARG                               $8      !0, !1
         12        SEND_FUNC_ARG                                            $8
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $7
   26    15    >   FETCH_DIM_R                                      ~10     !0, !1
         16      > RETURN                                                   ~10
   27    17*     > 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/Yfmub
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
   29     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/Yfmub
function name:  commentCount
number of ops:  9
compiled vars:  !0 = $cache
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   BIND_STATIC                                              !0
   38     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
   39     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/Yfmub
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
   29     5      > RETURN                                                   null

End of function __construct

End of class Post.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.97 ms | 1405 KiB | 17 Q