3v4l.org

run code in 500+ PHP versions simultaneously
<?php class User { public readonly int $id; public readonly string $email; public function __construct(int $id, string $email) { $this->id = $id; $this->email = $email; } } interface IUserStorage { public function addUser(User $user): void; public function findById(int $userId): ?User; public function findFirstByEmail(string $email): ?User; } class RuntimeUserStorage implements IUserStorage { private array $users; public function __construct(array $users = []) { $this->users = $users; } public function addUser(User $user): void { $this->users[$user->id] = $user; } public function findById(int $userId): ?User { return $this->users[$userId] ?? null; } public function findFirstByEmail(string $email): ?User { $usersWithEmail = array_filter($this->users, static fn(User $user) => $user->email === $email); return array_shift($usersWithEmail); } } interface IFindEmail { public function __invoke(string $email): ?string; } class FindEmailFromUsers implements IFindEmail { private IUserStorage $users; public function __construct(IUserStorage $users) { $this->users = $users; } public function __invoke(string $email): ?string { return $this->users->findFirstByEmail($email)?->email; } } class IsEmailValid { private IFindEmail $findEmail; public function __construct(IFindEmail $findEmail) { $this->findEmail = $findEmail; } public function __invoke(string $email): bool { return $this->isEmailUnique($email) && $this->isEmailValid($email) && $this->isEmailTooShort($email); } private function isEmailUnique(string $email): bool { $foundEmail = ($this->findEmail)($email); if(null === $foundEmail) { return true; } return $foundEmail !== $email; } private function isEmailValid(string $email): bool {return true;} private function isEmailTooShort(string $email): bool {return true;} } $user = new User(1, 'vasya@gmail.com'); $emailStorage = new RuntimeUserStorage(); $emailStorage->adduser($user); $isEmailValid = new IsEmailValid(new FindEmailFromUsers($emailStorage)); var_dump($isEmailValid($user->email)); var_dump($isEmailValid('petya@mail.ru'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  (null)
number of ops:  35
compiled vars:  !0 = $user, !1 = $emailStorage, !2 = $isEmailValid
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   DECLARE_CLASS                                                'runtimeuserstorage'
   45     1        DECLARE_CLASS                                                'findemailfromusers'
   85     2        NEW                                                  $3      'User'
          3        SEND_VAL_EX                                                  1
          4        SEND_VAL_EX                                                  'vasya%40gmail.com'
          5        DO_FCALL                                          0          
          6        ASSIGN                                                       !0, $3
   86     7        NEW                                                  $6      'RuntimeUserStorage'
          8        DO_FCALL                                          0          
          9        ASSIGN                                                       !1, $6
   87    10        INIT_METHOD_CALL                                             !1, 'adduser'
         11        SEND_VAR_EX                                                  !0
         12        DO_FCALL                                          0          
   88    13        NEW                                                  $10     'IsEmailValid'
         14        NEW                                                  $11     'FindEmailFromUsers'
         15        SEND_VAR_EX                                                  !1
         16        DO_FCALL                                          0          
         17        SEND_VAR_NO_REF_EX                                           $11
         18        DO_FCALL                                          0          
         19        ASSIGN                                                       !2, $10
   90    20        INIT_FCALL                                                   'var_dump'
         21        INIT_DYNAMIC_CALL                                            !2
         22        CHECK_FUNC_ARG                                               
         23        FETCH_OBJ_FUNC_ARG                                   $15     !0, 'email'
         24        SEND_FUNC_ARG                                                $15
         25        DO_FCALL                                          0  $16     
         26        SEND_VAR                                                     $16
         27        DO_ICALL                                                     
   91    28        INIT_FCALL                                                   'var_dump'
         29        INIT_DYNAMIC_CALL                                            !2
         30        SEND_VAL_EX                                                  'petya%40mail.ru'
         31        DO_FCALL                                          0  $18     
         32        SEND_VAR                                                     $18
         33        DO_ICALL                                                     
         34      > RETURN                                                       1

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

End of function __construct

End of class User.

Class IUserStorage:
Function adduser:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  addUser
number of ops:  2
compiled vars:  !0 = $user
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1      > RETURN                                                       null

End of function adduser

Function findbyid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  findById
number of ops:  3
compiled vars:  !0 = $userId
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
          1        VERIFY_RETURN_TYPE                                           
          2      > RETURN                                                       null

End of function findbyid

Function findfirstbyemail:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  findFirstByEmail
number of ops:  3
compiled vars:  !0 = $email
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   RECV                                                 !0      
          1        VERIFY_RETURN_TYPE                                           
          2      > RETURN                                                       null

End of function findfirstbyemail

End of class IUserStorage.

Class RuntimeUserStorage:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  __construct
number of ops:  4
compiled vars:  !0 = $users
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   RECV_INIT                                            !0      <array>
   23     1        ASSIGN_OBJ                                                   'users'
          2        OP_DATA                                                      !0
   24     3      > RETURN                                                       null

End of function __construct

Function adduser:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  addUser
number of ops:  6
compiled vars:  !0 = $user
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   RECV                                                 !0      
   27     1        FETCH_OBJ_R                                          ~2      !0, 'id'
          2        FETCH_OBJ_W                                          $1      'users'
          3        ASSIGN_DIM                                                   $1, ~2
          4        OP_DATA                                                      !0
   28     5      > RETURN                                                       null

End of function adduser

Function findbyid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  findById
number of ops:  9
compiled vars:  !0 = $userId
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   30     0  E >   RECV                                                 !0      
   31     1        FETCH_OBJ_IS                                         ~1      'users'
          2        FETCH_DIM_IS                                         ~2      ~1, !0
          3        COALESCE                                             ~3      ~2
          4        QM_ASSIGN                                            ~3      null
          5        VERIFY_RETURN_TYPE                                           ~3
          6      > RETURN                                                       ~3
   32     7*       VERIFY_RETURN_TYPE                                           
          8*     > RETURN                                                       null

End of function findbyid

Function findfirstbyemail:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  findFirstByEmail
number of ops:  16
compiled vars:  !0 = $email, !1 = $usersWithEmail
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   RECV                                                 !0      
   35     1        INIT_FCALL                                                   'array_filter'
          2        FETCH_OBJ_R                                          ~2      'users'
          3        SEND_VAL                                                     ~2
          4        DECLARE_LAMBDA_FUNCTION                              ~3      [0]
          5        BIND_LEXICAL                                                 ~3, !0
          6        SEND_VAL                                                     ~3
          7        DO_ICALL                                             $4      
          8        ASSIGN                                                       !1, $4
   37     9        INIT_FCALL                                                   'array_shift'
         10        SEND_REF                                                     !1
         11        DO_ICALL                                             $6      
         12        VERIFY_RETURN_TYPE                                           $6
         13      > RETURN                                                       $6
   38    14*       VERIFY_RETURN_TYPE                                           
         15*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  {closure:RuntimeUserStorage::findFirstByEmail():35}
number of ops:  6
compiled vars:  !0 = $user, !1 = $email
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   35     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
          2        FETCH_OBJ_R                                          ~2      !0, 'email'
          3        IS_IDENTICAL                                         ~3      !1, ~2
          4      > RETURN                                                       ~3
          5*     > RETURN                                                       null

End of Dynamic Function 0

End of function findfirstbyemail

End of class RuntimeUserStorage.

Class IFindEmail:
Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  __invoke
number of ops:  3
compiled vars:  !0 = $email
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   42     0  E >   RECV                                                 !0      
          1        VERIFY_RETURN_TYPE                                           
          2      > RETURN                                                       null

End of function __invoke

End of class IFindEmail.

Class FindEmailFromUsers:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  __construct
number of ops:  4
compiled vars:  !0 = $users
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   48     0  E >   RECV                                                 !0      
   49     1        ASSIGN_OBJ                                                   'users'
          2        OP_DATA                                                      !0
   50     3      > RETURN                                                       null

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  __invoke
number of ops:  11
compiled vars:  !0 = $email
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   52     0  E >   RECV                                                 !0      
   53     1        FETCH_OBJ_R                                          ~1      'users'
          2        INIT_METHOD_CALL                                             ~1, 'findFirstByEmail'
          3        SEND_VAR_EX                                                  !0
          4        DO_FCALL                                          0  $2      
          5        JMP_NULL                                             ~3      $2
          6        FETCH_OBJ_R                                          ~3      $2, 'email'
          7        VERIFY_RETURN_TYPE                                           ~3
          8      > RETURN                                                       ~3
   54     9*       VERIFY_RETURN_TYPE                                           
         10*     > RETURN                                                       null

End of function __invoke

End of class FindEmailFromUsers.

Class IsEmailValid:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  __construct
number of ops:  4
compiled vars:  !0 = $findEmail
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   60     0  E >   RECV                                                 !0      
   61     1        ASSIGN_OBJ                                                   'findEmail'
          2        OP_DATA                                                      !0
   62     3      > RETURN                                                       null

End of function __construct

Function __invoke:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
Branch analysis from position: 9
filename:       /in/ObHTt
function name:  __invoke
number of ops:  18
compiled vars:  !0 = $email
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   64     0  E >   RECV                                                 !0      
   65     1        INIT_METHOD_CALL                                             'isEmailUnique'
          2        SEND_VAR_EX                                                  !0
          3        DO_FCALL                                          0  $1      
          4      > JMPZ_EX                                              ~2      $1, ->9
   66     5    >   INIT_METHOD_CALL                                             'isEmailValid'
          6        SEND_VAR_EX                                                  !0
          7        DO_FCALL                                          0  $3      
          8        BOOL                                                 ~2      $3
          9    > > JMPZ_EX                                              ~2      ~2, ->14
   67    10    >   INIT_METHOD_CALL                                             'isEmailTooShort'
         11        SEND_VAR_EX                                                  !0
         12        DO_FCALL                                          0  $4      
         13        BOOL                                                 ~2      $4
         14    >   VERIFY_RETURN_TYPE                                           ~2
         15      > RETURN                                                       ~2
   68    16*       VERIFY_RETURN_TYPE                                           
         17*     > RETURN                                                       null

End of function __invoke

Function isemailunique:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  isEmailUnique
number of ops:  14
compiled vars:  !0 = $email, !1 = $foundEmail
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   70     0  E >   RECV                                                 !0      
   71     1        FETCH_OBJ_R                                          ~2      'findEmail'
          2        INIT_DYNAMIC_CALL                                            ~2
          3        SEND_VAR_EX                                                  !0
          4        DO_FCALL                                          0  $3      
          5        ASSIGN                                                       !1, $3
   73     6        TYPE_CHECK                                        2          !1
          7      > JMPZ                                                         ~5, ->9
   74     8    > > RETURN                                                       <true>
   77     9    >   IS_NOT_IDENTICAL                                     ~6      !1, !0
         10        VERIFY_RETURN_TYPE                                           ~6
         11      > RETURN                                                       ~6
   78    12*       VERIFY_RETURN_TYPE                                           
         13*     > RETURN                                                       null

End of function isemailunique

Function isemailvalid:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  isEmailValid
number of ops:  4
compiled vars:  !0 = $email
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   80     0  E >   RECV                                                 !0      
          1      > RETURN                                                       <true>
          2*       VERIFY_RETURN_TYPE                                           
          3*     > RETURN                                                       null

End of function isemailvalid

Function isemailtooshort:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ObHTt
function name:  isEmailTooShort
number of ops:  4
compiled vars:  !0 = $email
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   82     0  E >   RECV                                                 !0      
          1      > RETURN                                                       <true>
          2*       VERIFY_RETURN_TYPE                                           
          3*     > RETURN                                                       null

End of function isemailtooshort

End of class IsEmailValid.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.03 ms | 1647 KiB | 16 Q