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(); } } class Logger { public static function log(string $log): void { echo $log; } } class CommentCount { private $count; public function __construct(int $count) { $this->count = $count; } public function getCount(): int { return $this->count; } } class Post extends Model { public function commentCount(): CommentCount { try { return new CommentCount($this->comments->count()); } catch (Exception $e) { Logger::log($e->getMessage()); return new CommentCount(0); } } } $post = new Post(); $commentCount = $post->commentCount(); var_dump($commentCount->getCount()); var_dump($commentCount->getCount()); var_dump($commentCount->getCount()); var_dump($commentCount->getCount()); var_dump($commentCount->getCount());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/odnch
function name:  (null)
number of ops:  33
compiled vars:  !0 = $post, !1 = $commentCount
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   DECLARE_CLASS                                            'post', 'model'
   79     1        NEW                                              $2      'Post'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   80     4        INIT_METHOD_CALL                                         !0, 'commentCount'
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !1, $5
   82     7        INIT_FCALL                                               'var_dump'
          8        INIT_METHOD_CALL                                         !1, 'getCount'
          9        DO_FCALL                                      0  $7      
         10        SEND_VAR                                                 $7
         11        DO_ICALL                                                 
   83    12        INIT_FCALL                                               'var_dump'
         13        INIT_METHOD_CALL                                         !1, 'getCount'
         14        DO_FCALL                                      0  $9      
         15        SEND_VAR                                                 $9
         16        DO_ICALL                                                 
   84    17        INIT_FCALL                                               'var_dump'
         18        INIT_METHOD_CALL                                         !1, 'getCount'
         19        DO_FCALL                                      0  $11     
         20        SEND_VAR                                                 $11
         21        DO_ICALL                                                 
   85    22        INIT_FCALL                                               'var_dump'
         23        INIT_METHOD_CALL                                         !1, 'getCount'
         24        DO_FCALL                                      0  $13     
         25        SEND_VAR                                                 $13
         26        DO_ICALL                                                 
   86    27        INIT_FCALL                                               'var_dump'
         28        INIT_METHOD_CALL                                         !1, 'getCount'
         29        DO_FCALL                                      0  $15     
         30        SEND_VAR                                                 $15
         31        DO_ICALL                                                 
         32      > 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/odnch
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/odnch
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/odnch
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/odnch
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.

Class Logger:
Function log:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/odnch
function name:  log
number of ops:  3
compiled vars:  !0 = $log
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   46     1        ECHO                                                     !0
   47     2      > RETURN                                                   null

End of function log

End of class Logger.

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

End of function __construct

Function getcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/odnch
function name:  getCount
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   FETCH_OBJ_R                                      ~0      'count'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   62     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getcount

End of class CommentCount.

Class Post:
Function commentcount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 9
Branch analysis from position: 9
2 jumps found. (Code = 107) Position 1 = 10, Position 2 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/odnch
function name:  commentCount
number of ops:  22
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   70     0  E >   NEW                                              $1      'CommentCount'
          1        FETCH_OBJ_R                                      ~2      'comments'
          2        INIT_METHOD_CALL                                         ~2, 'count'
          3        DO_FCALL                                      0  $3      
          4        SEND_VAR_NO_REF_EX                                       $3
          5        DO_FCALL                                      0          
          6        VERIFY_RETURN_TYPE                                       $1
          7      > RETURN                                                   $1
          8*       JMP                                                      ->20
   72     9  E > > CATCH                                       last         'Exception'
   73    10    >   INIT_STATIC_METHOD_CALL                                  'Logger', 'log'
         11        INIT_METHOD_CALL                                         !0, 'getMessage'
         12        DO_FCALL                                      0  $5      
         13        SEND_VAR                                                 $5
         14        DO_FCALL                                      0          
   74    15        NEW                                              $7      'CommentCount'
         16        SEND_VAL_EX                                              0
         17        DO_FCALL                                      0          
         18        VERIFY_RETURN_TYPE                                       $7
         19      > RETURN                                                   $7
   76    20*       VERIFY_RETURN_TYPE                                       
         21*     > RETURN                                                   null

End of function commentcount

End of class Post.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.72 ms | 1408 KiB | 17 Q