3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DataObjectSecurityException extends Exception {}; abstract class DataObject { private $key; public function __construct(array $fields, string $key) { foreach($fields as $field => $value) { $this->$field = $value; } $this->key = $key; } public function export(string $key) { if ($key !== $this->key) { throw new DataObjectSecurityException("you are not authorized"); } return get_object_vars($this); } } class User extends DataObject { protected $id; protected $name; protected $hairColor; public function hi() { echo "Hi {$this->name}. You have nice {$this->hairColor} hair." . PHP_EOL; } public function dyeHair(string $color) { $this->hairColor = $color; } } // sample data as would be extracted from DB: $userData = ['id' => 11, 'name' => 'Jane Doe', 'hairColor' => 'brown']; $key = uniqid(); $user = new User($userData, $key); $user->hi(); echo "changing hair color" . PHP_EOL; $user->dyeHair('blue'); $user->hi(); // now retrieve the data if we want to update the DB $newUserData = $user->export($key); echo "new user data:" . PHP_EOL; var_dump($newUserData);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5DekW
function name:  (null)
number of ops:  26
compiled vars:  !0 = $userData, !1 = $key, !2 = $user, !3 = $newUserData
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   ASSIGN                                                   !0, <array>
   42     1        INIT_FCALL                                               'uniqid'
          2        DO_ICALL                                         $5      
          3        ASSIGN                                                   !1, $5
   44     4        NEW                                              $7      'User'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAR_EX                                              !1
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !2, $7
   45     9        INIT_METHOD_CALL                                         !2, 'hi'
         10        DO_FCALL                                      0          
   47    11        ECHO                                                     'changing+hair+color%0A'
   48    12        INIT_METHOD_CALL                                         !2, 'dyeHair'
         13        SEND_VAL_EX                                              'blue'
         14        DO_FCALL                                      0          
   49    15        INIT_METHOD_CALL                                         !2, 'hi'
         16        DO_FCALL                                      0          
   52    17        INIT_METHOD_CALL                                         !2, 'export'
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0  $13     
         20        ASSIGN                                                   !3, $13
   54    21        ECHO                                                     'new+user+data%3A%0A'
   55    22        INIT_FCALL                                               'var_dump'
         23        SEND_VAR                                                 !3
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Class DataObjectSecurityException: [no user functions]
Class DataObject:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/5DekW
function name:  __construct
number of ops:  12
compiled vars:  !0 = $fields, !1 = $key, !2 = $value, !3 = $field
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2      > FE_RESET_R                                       $4      !0, ->8
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->8
          4    >   ASSIGN                                                   !3, ~5
   10     5        ASSIGN_OBJ                                               !3
          6        OP_DATA                                                  !2
    9     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $4
   13     9        ASSIGN_OBJ                                               'key'
         10        OP_DATA                                                  !1
   14    11      > RETURN                                                   null

End of function __construct

Function export:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5DekW
function name:  export
number of ops:  14
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        FETCH_OBJ_R                                      ~1      'key'
          2        IS_NOT_IDENTICAL                                         !0, ~1
          3      > JMPZ                                                     ~2, ->8
   18     4    >   NEW                                              $3      'DataObjectSecurityException'
          5        SEND_VAL_EX                                              'you+are+not+authorized'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $3
   21     8    >   INIT_FCALL                                               'get_object_vars'
          9        FETCH_THIS                                       ~5      
         10        SEND_VAL                                                 ~5
         11        DO_ICALL                                         $6      
         12      > RETURN                                                   $6
   22    13*     > RETURN                                                   null

End of function export

End of class DataObject.

Class User:
Function hi:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5DekW
function name:  hi
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ROPE_INIT                                     5  ~3      'Hi+'
          1        FETCH_OBJ_R                                      ~0      'name'
          2        ROPE_ADD                                      1  ~3      ~3, ~0
          3        ROPE_ADD                                      2  ~3      ~3, '.++You+have+nice+'
          4        FETCH_OBJ_R                                      ~1      'hairColor'
          5        ROPE_ADD                                      3  ~3      ~3, ~1
          6        ROPE_END                                      4  ~2      ~3, '+hair.'
          7        CONCAT                                           ~6      ~2, '%0A'
          8        ECHO                                                     ~6
   32     9      > RETURN                                                   null

End of function hi

Function dyehair:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5DekW
function name:  dyeHair
number of ops:  4
compiled vars:  !0 = $color
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        ASSIGN_OBJ                                               'hairColor'
          2        OP_DATA                                                  !0
   36     3      > RETURN                                                   null

End of function dyehair

Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 8
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/5DekW
function name:  __construct
number of ops:  12
compiled vars:  !0 = $fields, !1 = $key, !2 = $value, !3 = $field
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2      > FE_RESET_R                                       $4      !0, ->8
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->8
          4    >   ASSIGN                                                   !3, ~5
   10     5        ASSIGN_OBJ                                               !3
          6        OP_DATA                                                  !2
    9     7      > JMP                                                      ->3
          8    >   FE_FREE                                                  $4
   13     9        ASSIGN_OBJ                                               'key'
         10        OP_DATA                                                  !1
   14    11      > RETURN                                                   null

End of function __construct

Function export:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5DekW
function name:  export
number of ops:  14
compiled vars:  !0 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        FETCH_OBJ_R                                      ~1      'key'
          2        IS_NOT_IDENTICAL                                         !0, ~1
          3      > JMPZ                                                     ~2, ->8
   18     4    >   NEW                                              $3      'DataObjectSecurityException'
          5        SEND_VAL_EX                                              'you+are+not+authorized'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $3
   21     8    >   INIT_FCALL                                               'get_object_vars'
          9        FETCH_THIS                                       ~5      
         10        SEND_VAL                                                 ~5
         11        DO_ICALL                                         $6      
         12      > RETURN                                                   $6
   22    13*     > RETURN                                                   null

End of function export

End of class User.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.5 ms | 1404 KiB | 19 Q