3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait CastableBehavior { public static function getFromContext($obj) { var_dump($obj, get_object_vars($obj)); $casted = new static; foreach (get_object_vars($obj) as $key => $value) { echo $key, '=>', $value, PHP_EOL; $casted->$key = $value; } return $casted; } } interface UserTypes { const USER = 1; const ADMIN = 2; const MODERATOR = 3; } class User { private $id; private $name; private $type; public function __construct($id, $name, $type) { $this->id = $id; $this->name = $name; $this->type = $type; } public function getID() { return $this->id; } public function getName() { return $this->name; } public function getType() { return $this->type; } } class Admin { use CastableBehavior; private $id; private $name; private $type; } $user = new User(2, 'John', UserTypes::ADMIN); if ($user->getType() === UserTypes::ADMIN) { $admin = Admin::getFromContext($user); } var_dump($admin);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/ERF0N
function name:  (null)
number of ops:  19
compiled vars:  !0 = $user, !1 = $admin
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   DECLARE_CLASS                                            'admin'
   54     1        NEW                                              $2      'User'
          2        SEND_VAL_EX                                              2
          3        SEND_VAL_EX                                              'John'
          4        SEND_VAL_EX                                              2
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $2
   55     7        INIT_METHOD_CALL                                         !0, 'getType'
          8        DO_FCALL                                      0  $5      
          9        IS_IDENTICAL                                             $5, 2
         10      > JMPZ                                                     ~6, ->15
   56    11    >   INIT_STATIC_METHOD_CALL                                  'Admin', 'getFromContext'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $7      
         14        ASSIGN                                                   !1, $7
   58    15    >   INIT_FCALL                                               'var_dump'
         16        SEND_VAR                                                 !1
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Class CastableBehavior:
Function getfromcontext:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 24
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 24
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/ERF0N
function name:  getFromContext
number of ops:  27
compiled vars:  !0 = $obj, !1 = $casted, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'var_dump'
          2        SEND_VAR                                                 !0
          3        INIT_FCALL                                               'get_object_vars'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $4      
          6        SEND_VAR                                                 $4
          7        DO_ICALL                                                 
    6     8        NEW                          static              $6      
          9        DO_FCALL                                      0          
         10        ASSIGN                                                   !1, $6
    7    11        INIT_FCALL                                               'get_object_vars'
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $9      
         14      > FE_RESET_R                                       $10     $9, ->24
         15    > > FE_FETCH_R                                       ~11     $10, !2, ->24
         16    >   ASSIGN                                                   !3, ~11
    8    17        ECHO                                                     !3
         18        ECHO                                                     '%3D%3E'
         19        ECHO                                                     !2
         20        ECHO                                                     '%0A'
    9    21        ASSIGN_OBJ                                               !1, !3
         22        OP_DATA                                                  !2
    7    23      > JMP                                                      ->15
         24    >   FE_FREE                                                  $10
   12    25      > RETURN                                                   !1
   13    26*     > RETURN                                                   null

End of function getfromcontext

End of class CastableBehavior.

Class UserTypes: [no user functions]
Class User:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ERF0N
function name:  __construct
number of ops:  10
compiled vars:  !0 = $id, !1 = $name, !2 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   28     3        ASSIGN_OBJ                                               'id'
          4        OP_DATA                                                  !0
   29     5        ASSIGN_OBJ                                               'name'
          6        OP_DATA                                                  !1
   30     7        ASSIGN_OBJ                                               'type'
          8        OP_DATA                                                  !2
   31     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/ERF0N
function name:  getID
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   FETCH_OBJ_R                                      ~0      'id'
          1      > RETURN                                                   ~0
   35     2*     > RETURN                                                   null

End of function getid

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

End of function getname

Function gettype:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ERF0N
function name:  getType
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   FETCH_OBJ_R                                      ~0      'type'
          1      > RETURN                                                   ~0
   43     2*     > RETURN                                                   null

End of function gettype

End of class User.

Class Admin: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.91 ms | 1404 KiB | 17 Q