3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Entity { public function getId() : int; } class Comment implements Entity { private int $id; private int $userId; private string $text; public function __construct(int $id, int $userId, string $text) { $this->id = $id; $this->userId = $userId; $this->text = $text; } public function getId() : int { return $this->id; } public function getUserId() : int { return $this->userId; } public function getText() : string { return $this->text; } public function setText(string $text): void { $this->text = $text; } } class CommentRepository { private array $entities = []; public function create(int $userId, string $text): Comment { $id = $this->generateId(); $entities[$id] = new Comment($id, $userId, $text); return $entities[$id]; } public function update(Comment $comment): Comment { $this->entities[$comment->getId()] = $comment; return $this->entities[$comment->getId()]; } private function generateId() : int { return random_int(1, 1000000); } } $repo = new CommentRepository; $comment = $repo->create(11, 'Test comment'); $comment->setText("updated comment"); $comment = $repo->update($comment); var_dump($comment);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FX4Ms
function name:  (null)
number of ops:  20
compiled vars:  !0 = $repo, !1 = $comment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   DECLARE_CLASS                                            'comment'
   65     1        NEW                                              $2      'CommentRepository'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   67     4        INIT_METHOD_CALL                                         !0, 'create'
          5        SEND_VAL_EX                                              11
          6        SEND_VAL_EX                                              'Test+comment'
          7        DO_FCALL                                      0  $5      
          8        ASSIGN                                                   !1, $5
   68     9        INIT_METHOD_CALL                                         !1, 'setText'
         10        SEND_VAL_EX                                              'updated+comment'
         11        DO_FCALL                                      0          
   69    12        INIT_METHOD_CALL                                         !0, 'update'
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0  $8      
         15        ASSIGN                                                   !1, $8
   71    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

Class Entity:
Function getid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FX4Ms
function name:  getId
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   VERIFY_RETURN_TYPE                                       
          1      > RETURN                                                   null

End of function getid

End of class Entity.

Class Comment:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FX4Ms
function name:  __construct
number of ops:  10
compiled vars:  !0 = $id, !1 = $userId, !2 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   16     3        ASSIGN_OBJ                                               'id'
          4        OP_DATA                                                  !0
   17     5        ASSIGN_OBJ                                               'userId'
          6        OP_DATA                                                  !1
   18     7        ASSIGN_OBJ                                               'text'
          8        OP_DATA                                                  !2
   19     9      > RETURN                                                   null

End of function __construct

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

End of function getid

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

End of function getuserid

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

End of function gettext

Function settext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FX4Ms
function name:  setText
number of ops:  4
compiled vars:  !0 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
   38     1        ASSIGN_OBJ                                               'text'
          2        OP_DATA                                                  !0
   39     3      > RETURN                                                   null

End of function settext

End of class Comment.

Class CommentRepository:
Function create:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FX4Ms
function name:  create
number of ops:  17
compiled vars:  !0 = $userId, !1 = $text, !2 = $id, !3 = $entities
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   47     2        INIT_METHOD_CALL                                         'generateId'
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !2, $4
   48     5        NEW                                              $7      'Comment'
          6        SEND_VAR_EX                                              !2
          7        SEND_VAR_EX                                              !0
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10        ASSIGN_DIM                                               !3, !2
         11        OP_DATA                                                  $7
   50    12        FETCH_DIM_R                                      ~9      !3, !2
         13        VERIFY_RETURN_TYPE                                       ~9
         14      > RETURN                                                   ~9
   51    15*       VERIFY_RETURN_TYPE                                       
         16*     > RETURN                                                   null

End of function create

Function update:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FX4Ms
function name:  update
number of ops:  14
compiled vars:  !0 = $comment
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   54     1        INIT_METHOD_CALL                                         !0, 'getId'
          2        DO_FCALL                                      0  $2      
          3        FETCH_OBJ_W                                      $1      'entities'
          4        ASSIGN_DIM                                               $1, $2
          5        OP_DATA                                                  !0
   56     6        INIT_METHOD_CALL                                         !0, 'getId'
          7        DO_FCALL                                      0  $5      
          8        FETCH_OBJ_R                                      ~4      'entities'
          9        FETCH_DIM_R                                      ~6      ~4, $5
         10        VERIFY_RETURN_TYPE                                       ~6
         11      > RETURN                                                   ~6
   57    12*       VERIFY_RETURN_TYPE                                       
         13*     > RETURN                                                   null

End of function update

Function generateid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FX4Ms
function name:  generateId
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   INIT_FCALL                                               'random_int'
          1        SEND_VAL                                                 1
          2        SEND_VAL                                                 1000000
          3        DO_ICALL                                         $0      
          4        VERIFY_RETURN_TYPE                                       $0
          5      > RETURN                                                   $0
   62     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function generateid

End of class CommentRepository.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.39 ms | 1404 KiB | 17 Q