3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Access a property with no restrictions function stole($object,$property){ $dict = (array)$object; $class = get_class($object); return isset($dict[$property])? $dict[$property]:(isset($dict["\0*\0$property"])? $dict["\0*\0$property"]:(isset($dict["\0$class\0$property"])? $dict["\0$class\0$property"]:null)); } // Modify a property with no restrictions function inject(&$object,$property,$value){ $dict = (array)$object; $class = get_class($object); if (isset($dict["\0$class\0$property"])) { $dict["\0$class\0$property"] = $value; $object = castToClass($dict,$class); } elseif (isset($dict["\0*\0$property"])) { $dict["\0*\0$property"] = $value; $object = castToClass($dict,$class); } elseif (isset($dict[$property])) { $object->$property = $value; } else { return ; } } // Required because we don't know if className has a __set_state defined. function castToClass(array $array,$className) { return unserialize( 'O:'.strlen($className).':"' .$className.'"'.strstr(serialize($array), ':') ); } // Example class Safe { private $content = 'gold'; } $mySafe = new Safe(); // Inject value into a private property inject($mySafe,'content','Magic!'); echo "I've robbed your ",stole($mySafe,'content'),"!";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LvYhp
function name:  (null)
number of ops:  16
compiled vars:  !0 = $mySafe
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   NEW                                              $1      'Safe'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   48     3        INIT_FCALL                                               'inject'
          4        SEND_REF                                                 !0
          5        SEND_VAL                                                 'content'
          6        SEND_VAL                                                 'Magic%21'
          7        DO_FCALL                                      0          
   51     8        ECHO                                                     'I%27ve+robbed+your+'
          9        INIT_FCALL                                               'stole'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 'content'
         12        DO_FCALL                                      0  $5      
         13        ECHO                                                     $5
         14        ECHO                                                     '%21'
         15      > RETURN                                                   1

Function stole:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 33
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LvYhp
function name:  stole
number of ops:  38
compiled vars:  !0 = $object, !1 = $property, !2 = $dict, !3 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        CAST                                          7  ~4      !0
          3        ASSIGN                                                   !2, ~4
    5     4        GET_CLASS                                        ~6      !0
          5        ASSIGN                                                   !3, ~6
    6     6        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !1
          7      > JMPZ                                                     ~8, ->11
    7     8    >   FETCH_DIM_R                                      ~9      !2, !1
          9        QM_ASSIGN                                        ~10     ~9
         10      > JMP                                                      ->36
         11    >   NOP                                                      
         12        FAST_CONCAT                                      ~11     '%00%2A%00', !1
         13        ISSET_ISEMPTY_DIM_OBJ                         0          !2, ~11
         14      > JMPZ                                                     ~12, ->20
    8    15    >   NOP                                                      
         16        FAST_CONCAT                                      ~13     '%00%2A%00', !1
         17        FETCH_DIM_R                                      ~14     !2, ~13
         18        QM_ASSIGN                                        ~15     ~14
         19      > JMP                                                      ->35
         20    >   ROPE_INIT                                     4  ~17     '%00'
         21        ROPE_ADD                                      1  ~17     ~17, !3
         22        ROPE_ADD                                      2  ~17     ~17, '%00'
         23        ROPE_END                                      3  ~16     ~17, !1
         24        ISSET_ISEMPTY_DIM_OBJ                         0          !2, ~16
         25      > JMPZ                                                     ~19, ->33
    9    26    >   ROPE_INIT                                     4  ~21     '%00'
         27        ROPE_ADD                                      1  ~21     ~21, !3
         28        ROPE_ADD                                      2  ~21     ~21, '%00'
         29        ROPE_END                                      3  ~20     ~21, !1
         30        FETCH_DIM_R                                      ~23     !2, ~20
         31        QM_ASSIGN                                        ~24     ~23
         32      > JMP                                                      ->34
         33    >   QM_ASSIGN                                        ~24     null
         34    >   QM_ASSIGN                                        ~15     ~24
         35    >   QM_ASSIGN                                        ~10     ~15
         36    > > RETURN                                                   ~10
   10    37*     > RETURN                                                   null

End of function stole

Function inject:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 25
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 39
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LvYhp
function name:  inject
number of ops:  46
compiled vars:  !0 = $object, !1 = $property, !2 = $value, !3 = $dict, !4 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   15     3        CAST                                          7  ~5      !0
          4        ASSIGN                                                   !3, ~5
   16     5        GET_CLASS                                        ~7      !0
          6        ASSIGN                                                   !4, ~7
   17     7        ROPE_INIT                                     4  ~10     '%00'
          8        ROPE_ADD                                      1  ~10     ~10, !4
          9        ROPE_ADD                                      2  ~10     ~10, '%00'
         10        ROPE_END                                      3  ~9      ~10, !1
         11        ISSET_ISEMPTY_DIM_OBJ                         0          !3, ~9
         12      > JMPZ                                                     ~12, ->25
   18    13    >   ROPE_INIT                                     4  ~14     '%00'
         14        ROPE_ADD                                      1  ~14     ~14, !4
         15        ROPE_ADD                                      2  ~14     ~14, '%00'
         16        ROPE_END                                      3  ~13     ~14, !1
         17        ASSIGN_DIM                                               !3, ~13
         18        OP_DATA                                                  !2
   19    19        INIT_FCALL_BY_NAME                                       'castToClass'
         20        SEND_VAR_EX                                              !3
         21        SEND_VAR_EX                                              !4
         22        DO_FCALL                                      0  $17     
         23        ASSIGN                                                   !0, $17
         24      > JMP                                                      ->45
   20    25    >   NOP                                                      
         26        FAST_CONCAT                                      ~19     '%00%2A%00', !1
         27        ISSET_ISEMPTY_DIM_OBJ                         0          !3, ~19
         28      > JMPZ                                                     ~20, ->39
   21    29    >   NOP                                                      
         30        FAST_CONCAT                                      ~21     '%00%2A%00', !1
         31        ASSIGN_DIM                                               !3, ~21
         32        OP_DATA                                                  !2
   22    33        INIT_FCALL_BY_NAME                                       'castToClass'
         34        SEND_VAR_EX                                              !3
         35        SEND_VAR_EX                                              !4
         36        DO_FCALL                                      0  $23     
         37        ASSIGN                                                   !0, $23
         38      > JMP                                                      ->45
   23    39    >   ISSET_ISEMPTY_DIM_OBJ                         0          !3, !1
         40      > JMPZ                                                     ~25, ->44
   24    41    >   ASSIGN_OBJ                                               !0, !1
         42        OP_DATA                                                  !2
         43      > JMP                                                      ->45
   26    44    > > RETURN                                                   null
   28    45    > > RETURN                                                   null

End of function inject

Function casttoclass:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LvYhp
function name:  castToClass
number of ops:  20
compiled vars:  !0 = $array, !1 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   32     2        INIT_FCALL                                               'unserialize'
   33     3        STRLEN                                           ~2      !1
          4        CONCAT                                           ~3      'O%3A', ~2
          5        CONCAT                                           ~4      ~3, '%3A%22'
   34     6        CONCAT                                           ~5      ~4, !1
          7        CONCAT                                           ~6      ~5, '%22'
          8        INIT_FCALL                                               'strstr'
          9        INIT_FCALL                                               'serialize'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $7      
         12        SEND_VAR                                                 $7
         13        SEND_VAL                                                 '%3A'
         14        DO_ICALL                                         $8      
         15        CONCAT                                           ~9      ~6, $8
         16        SEND_VAL                                                 ~9
         17        DO_ICALL                                         $10     
         18      > RETURN                                                   $10
   36    19*     > RETURN                                                   null

End of function casttoclass

Class Safe: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.1 ms | 1410 KiB | 21 Q