3v4l.org

run code in 500+ PHP versions simultaneously
<?php class CommentBase { private int $userId; private string $text; public function __construct(int $userId, string $text) { $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) { $this->text = $text; } } interface Entity { public function getId() : int; } class Comment extends CommentBase implements Entity { private int $id; public function __construct(int $id, int $userId, string $text) { $this->id = $id; parent::__construct($userId, $text); } public function getId() : int { return $this->id; } } class CommentRepository { private array $entities = []; public function create(CommentBase $comment): Comment { $id = $this->generateId(); $entities[$id] = new Comment($id, $comment->getUserId(), $comment->getText()); 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(new CommentBase(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/k7CDM
function name:  (null)
number of ops:  23
compiled vars:  !0 = $repo, !1 = $comment
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   39     0  E >   DECLARE_CLASS                                                'comment', 'commentbase'
   77     1        NEW                                                  $2      'CommentRepository'
          2        DO_FCALL                                          0          
          3        ASSIGN                                                       !0, $2
   79     4        INIT_METHOD_CALL                                             !0, 'create'
          5        NEW                                                  $5      'CommentBase'
          6        SEND_VAL_EX                                                  11
          7        SEND_VAL_EX                                                  'Test+comment'
          8        DO_FCALL                                          0          
          9        SEND_VAR_NO_REF_EX                                           $5
         10        DO_FCALL                                          0  $7      
         11        ASSIGN                                                       !1, $7
   80    12        INIT_METHOD_CALL                                             !1, 'setText'
         13        SEND_VAL_EX                                                  'updated+comment'
         14        DO_FCALL                                          0          
   81    15        INIT_METHOD_CALL                                             !0, 'update'
         16        SEND_VAR_EX                                                  !1
         17        DO_FCALL                                          0  $10     
         18        ASSIGN                                                       !1, $10
   83    19        INIT_FCALL                                                   'var_dump'
         20        SEND_VAR                                                     !1
         21        DO_ICALL                                                     
         22      > RETURN                                                       1

Class CommentBase:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k7CDM
function name:  __construct
number of ops:  7
compiled vars:  !0 = $userId, !1 = $text
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   10     2        ASSIGN_OBJ                                                   'userId'
          3        OP_DATA                                                      !0
   11     4        ASSIGN_OBJ                                                   'text'
          5        OP_DATA                                                      !1
   12     6      > 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/k7CDM
function name:  getId
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   FETCH_OBJ_R                                          ~0      'id'
          1        VERIFY_RETURN_TYPE                                           ~0
          2      > RETURN                                                       ~0
   17     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/k7CDM
function name:  getUserId
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   21     0  E >   FETCH_OBJ_R                                          ~0      'userId'
          1        VERIFY_RETURN_TYPE                                           ~0
          2      > RETURN                                                       ~0
   22     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/k7CDM
function name:  getText
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   FETCH_OBJ_R                                          ~0      'text'
          1        VERIFY_RETURN_TYPE                                           ~0
          2      > RETURN                                                       ~0
   27     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/k7CDM
function name:  setText
number of ops:  4
compiled vars:  !0 = $text
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   29     0  E >   RECV                                                 !0      
   31     1        ASSIGN_OBJ                                                   'text'
          2        OP_DATA                                                      !0
   32     3      > RETURN                                                       null

End of function settext

End of class CommentBase.

Class Entity:
Function getid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k7CDM
function name:  getId
number of ops:  2
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   36     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/k7CDM
function name:  __construct
number of ops:  10
compiled vars:  !0 = $id, !1 = $userId, !2 = $text
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   43     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   45     3        ASSIGN_OBJ                                                   'id'
          4        OP_DATA                                                      !0
   46     5        INIT_STATIC_METHOD_CALL                                      
          6        SEND_VAR_EX                                                  !1
          7        SEND_VAR_EX                                                  !2
          8        DO_FCALL                                          0          
   47     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/k7CDM
function name:  getId
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   51     0  E >   FETCH_OBJ_R                                          ~0      'id'
          1        VERIFY_RETURN_TYPE                                           ~0
          2      > RETURN                                                       ~0
   52     3*       VERIFY_RETURN_TYPE                                           
          4*     > RETURN                                                       null

End of function getid

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/k7CDM
function name:  create
number of ops:  20
compiled vars:  !0 = $comment, !1 = $id, !2 = $entities
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   58     0  E >   RECV                                                 !0      
   59     1        INIT_METHOD_CALL                                             'generateId'
          2        DO_FCALL                                          0  $3      
          3        ASSIGN                                                       !1, $3
   60     4        NEW                                                  $6      'Comment'
          5        SEND_VAR_EX                                                  !1
          6        INIT_METHOD_CALL                                             !0, 'getUserId'
          7        DO_FCALL                                          0  $7      
          8        SEND_VAR_NO_REF_EX                                           $7
          9        INIT_METHOD_CALL                                             !0, 'getText'
         10        DO_FCALL                                          0  $8      
         11        SEND_VAR_NO_REF_EX                                           $8
         12        DO_FCALL                                          0          
         13        ASSIGN_DIM                                                   !2, !1
         14        OP_DATA                                                      $6
   62    15        FETCH_DIM_R                                          ~10     !2, !1
         16        VERIFY_RETURN_TYPE                                           ~10
         17      > RETURN                                                       ~10
   63    18*       VERIFY_RETURN_TYPE                                           
         19*     > 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/k7CDM
function name:  update
number of ops:  14
compiled vars:  !0 = $comment
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   65     0  E >   RECV                                                 !0      
   66     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
   68     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
   69    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/k7CDM
function name:  generateId
number of ops:  8
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   73     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
   74     6*       VERIFY_RETURN_TYPE                                           
          7*     > RETURN                                                       null

End of function generateid

End of class CommentRepository.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.16 ms | 1283 KiB | 15 Q