3v4l.org

run code in 300+ PHP versions simultaneously
<?php try { $user = User_DTO::fromApiArray([ 'id' => 1, 'name' => 'Foo', 'username' => 'foo', 'email' => '', 'address' => [ 'street' => '', 'suite' => '', 'city' => '', 'zipcode' => '', 'geo' => [ 'lat' => '', 'lng' => '', ], ], 'phone' => '', 'website' => '', 'company' => [ 'name' => '', 'catchPhrase' => '', 'bs' => '', ], ]); echo $user->get_id() . PHP_EOL; echo $user->get_name() . PHP_EOL; echo $user->get_username() . PHP_EOL; } catch(Exception $e) { echo $e->getMessage(); } class User_DTO { private int $id; private string $name; private string $username; // force use of named constructors private function __construct() { } public static function fromApiArray($array): static { $inst = new static; $inst->id = (int) $array['id']; $inst->name = (string) $array['name']; $inst->username = (string) $array['username']; return $inst; } public function get_id(): int { return $this->id; } public function get_name(): string { return $this->name; } public function get_username(): string { return $this->username; } // etc }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 17
Branch analysis from position: 17
2 jumps found. (Code = 107) Position 1 = 18, Position 2 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dcMeV
function name:  (null)
number of ops:  22
compiled vars:  !0 = $user, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_STATIC_METHOD_CALL                                  'User_DTO', 'fromApiArray'
    5     1        SEND_VAL_EX                                              <array>
          2        DO_FCALL                                      0  $2      
    4     3        ASSIGN                                                   !0, $2
   28     4        INIT_METHOD_CALL                                         !0, 'get_id'
          5        DO_FCALL                                      0  $4      
          6        CONCAT                                           ~5      $4, '%0A'
          7        ECHO                                                     ~5
   29     8        INIT_METHOD_CALL                                         !0, 'get_name'
          9        DO_FCALL                                      0  $6      
         10        CONCAT                                           ~7      $6, '%0A'
         11        ECHO                                                     ~7
   30    12        INIT_METHOD_CALL                                         !0, 'get_username'
         13        DO_FCALL                                      0  $8      
         14        CONCAT                                           ~9      $8, '%0A'
         15        ECHO                                                     ~9
         16      > JMP                                                      ->21
   31    17  E > > CATCH                                       last         'Exception'
   32    18    >   INIT_METHOD_CALL                                         !1, 'getMessage'
         19        DO_FCALL                                      0  $10     
         20        ECHO                                                     $10
   67    21    > > RETURN                                                   1

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

End of function __construct

Function fromapiarray:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dcMeV
function name:  fromApiArray
number of ops:  20
compiled vars:  !0 = $array, !1 = $inst
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
   45     1        NEW                          static              $2      
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $2
   47     4        FETCH_DIM_R                                      ~6      !0, 'id'
          5        CAST                                          4  ~7      ~6
          6        ASSIGN_OBJ                                               !1, 'id'
          7        OP_DATA                                                  ~7
   48     8        FETCH_DIM_R                                      ~9      !0, 'name'
          9        CAST                                          6  ~10     ~9
         10        ASSIGN_OBJ                                               !1, 'name'
         11        OP_DATA                                                  ~10
   49    12        FETCH_DIM_R                                      ~12     !0, 'username'
         13        CAST                                          6  ~13     ~12
         14        ASSIGN_OBJ                                               !1, 'username'
         15        OP_DATA                                                  ~13
   51    16        VERIFY_RETURN_TYPE                                       !1
         17      > RETURN                                                   !1
   52    18*       VERIFY_RETURN_TYPE                                       
         19*     > RETURN                                                   null

End of function fromapiarray

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

End of function get_id

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

End of function get_name

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

End of function get_username

End of class User_DTO.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.6 ms | 1399 KiB | 13 Q