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 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/1luHe
function name:  (null)
number of ops:  32
compiled vars:  !0 = $post, !1 = $commentCount
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   69     0  E >   NEW                                              $2      'Post'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   70     3        INIT_METHOD_CALL                                         !0, 'commentCount'
          4        DO_FCALL                                      0  $5      
          5        ASSIGN                                                   !1, $5
   72     6        INIT_FCALL                                               'var_dump'
          7        INIT_METHOD_CALL                                         !1, 'getCount'
          8        DO_FCALL                                      0  $7      
          9        SEND_VAR                                                 $7
         10        DO_ICALL                                                 
   73    11        INIT_FCALL                                               'var_dump'
         12        INIT_METHOD_CALL                                         !1, 'getCount'
         13        DO_FCALL                                      0  $9      
         14        SEND_VAR                                                 $9
         15        DO_ICALL                                                 
   74    16        INIT_FCALL                                               'var_dump'
         17        INIT_METHOD_CALL                                         !1, 'getCount'
         18        DO_FCALL                                      0  $11     
         19        SEND_VAR                                                 $11
         20        DO_ICALL                                                 
   75    21        INIT_FCALL                                               'var_dump'
         22        INIT_METHOD_CALL                                         !1, 'getCount'
         23        DO_FCALL                                      0  $13     
         24        SEND_VAR                                                 $13
         25        DO_ICALL                                                 
   76    26        INIT_FCALL                                               'var_dump'
         27        INIT_METHOD_CALL                                         !1, 'getCount'
         28        DO_FCALL                                      0  $15     
         29        SEND_VAR                                                 $15
         30        DO_ICALL                                                 
         31      > 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/1luHe
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/1luHe
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 Logger:
Function log:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1luHe
function name:  log
number of ops:  3
compiled vars:  !0 = $log
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   36     1        ECHO                                                     !0
   37     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/1luHe
function name:  __construct
number of ops:  4
compiled vars:  !0 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   46     1        ASSIGN_OBJ                                               'count'
          2        OP_DATA                                                  !0
   47     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/1luHe
function name:  getCount
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   FETCH_OBJ_R                                      ~0      'count'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   52     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/1luHe
function name:  commentCount
number of ops:  22
compiled vars:  !0 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     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
   62     9  E > > CATCH                                       last         'Exception'
   63    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          
   64    15        NEW                                              $7      'CommentCount'
         16        SEND_VAL_EX                                              0
         17        DO_FCALL                                      0          
         18        VERIFY_RETURN_TYPE                                       $7
         19      > RETURN                                                   $7
   66    20*       VERIFY_RETURN_TYPE                                       
         21*     > 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/1luHe
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:
151.82 ms | 1469 KiB | 15 Q