3v4l.org

run code in 500+ 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 CommentWow { public function wow(CommentCount $commentCount): string { if ($commentCount->getCount() == 0) { return "Sad. :("; } if ($commentCount->getCount() > 0 && $commentCount->getCount() < 5) { return "Ok."; } if ($commentCount->getCount() >= 5) { return "Wow! :)"; } } } 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(); $wow = new CommentWow(); var_dump($wow->wow($commentCount)); var_dump($wow->wow($commentCount)); var_dump($wow->wow($commentCount)); var_dump($wow->wow($commentCount)); var_dump($wow->wow($commentCount));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/pCg4d
function name:  (null)
number of ops:  40
compiled vars:  !0 = $post, !1 = $commentCount, !2 = $wow
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   87     0  E >   NEW                                                  $3      'Post'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $3
   88     3        INIT_METHOD_CALL                                             !0, 'commentCount'
          4        DO_FCALL                                          0  $6      
          5        ASSIGN                                                       !1, $6
   90     6        NEW                                                  $8      'CommentWow'
          7        DO_FCALL                                          0          
          8        ASSIGN                                                       !2, $8
   92     9        INIT_FCALL                                                   'var_dump'
         10        INIT_METHOD_CALL                                             !2, 'wow'
         11        SEND_VAR_EX                                                  !1
         12        DO_FCALL                                          0  $11     
         13        SEND_VAR                                                     $11
         14        DO_ICALL                                                     
   93    15        INIT_FCALL                                                   'var_dump'
         16        INIT_METHOD_CALL                                             !2, 'wow'
         17        SEND_VAR_EX                                                  !1
         18        DO_FCALL                                          0  $13     
         19        SEND_VAR                                                     $13
         20        DO_ICALL                                                     
   94    21        INIT_FCALL                                                   'var_dump'
         22        INIT_METHOD_CALL                                             !2, 'wow'
         23        SEND_VAR_EX                                                  !1
         24        DO_FCALL                                          0  $15     
         25        SEND_VAR                                                     $15
         26        DO_ICALL                                                     
   95    27        INIT_FCALL                                                   'var_dump'
         28        INIT_METHOD_CALL                                             !2, 'wow'
         29        SEND_VAR_EX                                                  !1
         30        DO_FCALL                                          0  $17     
         31        SEND_VAR                                                     $17
         32        DO_ICALL                                                     
   96    33        INIT_FCALL                                                   'var_dump'
         34        INIT_METHOD_CALL                                             !2, 'wow'
         35        SEND_VAR_EX                                                  !1
         36        DO_FCALL                                          0  $19     
         37        SEND_VAR                                                     $19
         38        DO_ICALL                                                     
         39      > 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/pCg4d
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/pCg4d
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                                   <undef> 
          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/pCg4d
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/pCg4d
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/pCg4d
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 CommentWow:
Function wow:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 21
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/pCg4d
function name:  wow
number of ops:  23
compiled vars:  !0 = $commentCount
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   57     0  E >   RECV                                                 !0      
   59     1        INIT_METHOD_CALL                                             !0, 'getCount'
          2        DO_FCALL                                          0  $1      
          3        IS_EQUAL                                                     $1, 0
          4      > JMPZ                                                         ~2, ->6
   60     5    > > RETURN                                                       'Sad.+%3A%28'
   63     6    >   INIT_METHOD_CALL                                             !0, 'getCount'
          7        DO_FCALL                                          0  $3      
          8        IS_SMALLER                                           ~4      0, $3
          9      > JMPZ_EX                                              ~4      ~4, ->14
         10    >   INIT_METHOD_CALL                                             !0, 'getCount'
         11        DO_FCALL                                          0  $5      
         12        IS_SMALLER                                           ~6      $5, 5
         13        BOOL                                                 ~4      ~6
         14    > > JMPZ                                                         ~4, ->16
   64    15    > > RETURN                                                       'Ok.'
   67    16    >   INIT_METHOD_CALL                                             !0, 'getCount'
         17        DO_FCALL                                          0  $7      
         18        IS_SMALLER_OR_EQUAL                                          5, $7
         19      > JMPZ                                                         ~8, ->21
   68    20    > > RETURN                                                       'Wow%21+%3A%29'
   70    21    >   VERIFY_RETURN_TYPE                                           
         22      > RETURN                                                       null

End of function wow

End of class CommentWow.

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/pCg4d
function name:  commentCount
number of ops:  22
compiled vars:  !0 = $e
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   78     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
   80     9  E > > CATCH                                           last         'Exception'
   81    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          
   82    15        NEW                                                  $7      'CommentCount'
         16        SEND_VAL_EX                                                  0
         17        DO_FCALL                                          0          
         18        VERIFY_RETURN_TYPE                                           $7
         19      > RETURN                                                       $7
   84    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/pCg4d
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                                   <undef> 
          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.5.0


preferences:
157.57 ms | 1329 KiB | 16 Q