3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Entity { public function getId() : ?int; } class Comment implements Entity { private ?int $id = null; 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 setId(int $id) : void { $this->id = $id; } } class PseudoDatabase { private array $entities = []; public function save(Entity $entity) { $id = $entity->getId(); if (null === $id) { $id = $this->generateId(); $entity->setId($id); } $this->entities[$id] = $entity; } private function generateId() : int { return random_int(1, 1000000); } } $comment = new Comment(11, 'Test comment'); $database = new PseudoDatabase; $database->save($comment); var_dump($comment);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B1PQL
function name:  (null)
number of ops:  16
compiled vars:  !0 = $comment, !1 = $database
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   DECLARE_CLASS                                            'comment'
   51     1        NEW                                              $2      'Comment'
          2        SEND_VAL_EX                                              11
          3        SEND_VAL_EX                                              'Test+comment'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $2
   52     6        NEW                                              $5      'PseudoDatabase'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $5
   54     9        INIT_METHOD_CALL                                         !1, 'save'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0          
   56    12        INIT_FCALL                                               'var_dump'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                                 
         15      > RETURN                                                   1

Class Entity:
Function getid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B1PQL
function name:  getId
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     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/B1PQL
function name:  __construct
number of ops:  7
compiled vars:  !0 = $userId, !1 = $text
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        ASSIGN_OBJ                                               'userId'
          3        OP_DATA                                                  !0
   16     4        ASSIGN_OBJ                                               'text'
          5        OP_DATA                                                  !1
   17     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/B1PQL
function name:  getId
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   FETCH_OBJ_R                                      ~0      'id'
          1        VERIFY_RETURN_TYPE                                       ~0
          2      > RETURN                                                   ~0
   22     3*       VERIFY_RETURN_TYPE                                       
          4*     > RETURN                                                   null

End of function getid

Function setid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B1PQL
function name:  setId
number of ops:  4
compiled vars:  !0 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
   26     1        ASSIGN_OBJ                                               'id'
          2        OP_DATA                                                  !0
   27     3      > RETURN                                                   null

End of function setid

End of class Comment.

Class PseudoDatabase:
Function save:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/B1PQL
function name:  save
number of ops:  16
compiled vars:  !0 = $entity, !1 = $id
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
   34     1        INIT_METHOD_CALL                                         !0, 'getId'
          2        DO_FCALL                                      0  $2      
          3        ASSIGN                                                   !1, $2
   36     4        TYPE_CHECK                                    2          !1
          5      > JMPZ                                                     ~4, ->12
   37     6    >   INIT_METHOD_CALL                                         'generateId'
          7        DO_FCALL                                      0  $5      
          8        ASSIGN                                                   !1, $5
   39     9        INIT_METHOD_CALL                                         !0, 'setId'
         10        SEND_VAR_EX                                              !1
         11        DO_FCALL                                      0          
   42    12    >   FETCH_OBJ_W                                      $8      'entities'
         13        ASSIGN_DIM                                               $8, !1
         14        OP_DATA                                                  !0
   43    15      > RETURN                                                   null

End of function save

Function generateid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/B1PQL
function name:  generateId
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     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
   48     6*       VERIFY_RETURN_TYPE                                       
          7*     > RETURN                                                   null

End of function generateid

End of class PseudoDatabase.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.63 ms | 1004 KiB | 15 Q