3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Challenge 1: Modify Test::$secret before it's output. Rules:: 1. No use of Reflection API / runkit extension 2. No stopping execution before Test::run() 3. No Exceptions or PHP errors / warnings notices allowed Hints: 1. Caesar 2. Magic methods 3. Requires a new feature of PHP 5.4 */ class Test { private $secret = 'Nyy lbhe Onfr ner orybat gb hf.'; private $callback; final public function run() { call_user_func($this->callback); return $this->secret . PHP_EOL; } public function __set($k, $v) { $key = $v[($v[$v])]; // $v is some kind of weird array //var_dump('key:::::'.$key); $value = $v(); // and a callback! $this->{$key} = $value; } } $test = new Test; // start editing here /* function decode($N,$alphabet,$msg){ // Initialization $M = count($alphabet); $decrypt = array(); $decode = array(); $encrypted = preg_split("//",$msg, -1, PREG_SPLIT_NO_EMPTY); // Compute the decoding map $decode[' '] = ' '; foreach ($alphabet as $n=>$v){ $decode[$v] = $alphabet[($M+($n-$N)) % $M]; // Compute the decoding map for $v } foreach ($encrypted as $v){ $decrypt[] = $decode[$v]; } return join('',$decrypt); } $array = (array) $test; reset($array); $first_key = key($array); print_r($array[$first_key]); //used this to figure out the count: // http://rumkin.com/tools/cipher/caesar.php $key = decode(13,26, $array[$first_key]); */ function caesar($str, $n) { $ret = ""; for($i = 0, $l = strlen($str); $i < $l; ++$i) { $c = ord($str[$i]); if (97 <= $c && $c < 123) { $ret.= chr(($c + $n + 7) % 26 + 97); } else if(65 <= $c && $c < 91) { $ret.= chr(($c + $n + 13) % 26 + 65); } else { $ret.= $str[$i]; } } return $ret; } $array = (array) $test; reset($array); $first_key = key($array); print_r($array[$first_key]); $secret = caesar($array[$first_key],13); //print_r('the secret is:'.$secret); //$test->__set($secret , $secret[$secret]['yum']); $test->__set('secret' , $secret[$secret[0]]); // end editing here echo $test->run();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LPejB
function name:  (null)
number of ops:  33
compiled vars:  !0 = $test, !1 = $array, !2 = $first_key, !3 = $secret
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   NEW                                              $4      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   99     3        CAST                                          7  ~7      !0
          4        ASSIGN                                                   !1, ~7
  101     5        INIT_FCALL                                               'reset'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                                 
  102     8        INIT_FCALL                                               'key'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $10     
         11        ASSIGN                                                   !2, $10
  104    12        INIT_FCALL                                               'print_r'
         13        FETCH_DIM_R                                      ~12     !1, !2
         14        SEND_VAL                                                 ~12
         15        DO_ICALL                                                 
  107    16        INIT_FCALL                                               'caesar'
         17        FETCH_DIM_R                                      ~14     !1, !2
         18        SEND_VAL                                                 ~14
         19        SEND_VAL                                                 13
         20        DO_FCALL                                      0  $15     
         21        ASSIGN                                                   !3, $15
  113    22        INIT_METHOD_CALL                                         !0, '__set'
         23        SEND_VAL_EX                                              'secret'
         24        CHECK_FUNC_ARG                                           
         25        FETCH_DIM_R                                      ~17     !3, 0
         26        FETCH_DIM_FUNC_ARG                               $18     !3, ~17
         27        SEND_FUNC_ARG                                            $18
         28        DO_FCALL                                      0          
  118    29        INIT_METHOD_CALL                                         !0, 'run'
         30        DO_FCALL                                      0  $20     
         31        ECHO                                                     $20
         32      > RETURN                                                   1

Function caesar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 43
Branch analysis from position: 43
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 7
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 46) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 7
Branch analysis from position: 45
Branch analysis from position: 7
Branch analysis from position: 26
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 40
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 45, Position 2 = 7
Branch analysis from position: 45
Branch analysis from position: 7
Branch analysis from position: 30
Branch analysis from position: 16
filename:       /in/LPejB
function name:  caesar
number of ops:  47
compiled vars:  !0 = $str, !1 = $n, !2 = $ret, !3 = $i, !4 = $l, !5 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   83     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   85     2        ASSIGN                                                   !2, ''
   86     3        ASSIGN                                                   !3, 0
          4        STRLEN                                           ~8      !0
          5        ASSIGN                                                   !4, ~8
          6      > JMP                                                      ->43
   87     7    >   INIT_FCALL                                               'ord'
          8        FETCH_DIM_R                                      ~10     !0, !3
          9        SEND_VAL                                                 ~10
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !5, $11
   88    12        IS_SMALLER_OR_EQUAL                              ~13     97, !5
         13      > JMPZ_EX                                          ~13     ~13, ->16
         14    >   IS_SMALLER                                       ~14     !5, 123
         15        BOOL                                             ~13     ~14
         16    > > JMPZ                                                     ~13, ->26
   89    17    >   INIT_FCALL                                               'chr'
         18        ADD                                              ~15     !5, !1
         19        ADD                                              ~16     ~15, 7
         20        MOD                                              ~17     ~16, 26
         21        ADD                                              ~18     ~17, 97
         22        SEND_VAL                                                 ~18
         23        DO_ICALL                                         $19     
         24        ASSIGN_OP                                     8          !2, $19
         25      > JMP                                                      ->42
   90    26    >   IS_SMALLER_OR_EQUAL                              ~21     65, !5
         27      > JMPZ_EX                                          ~21     ~21, ->30
         28    >   IS_SMALLER                                       ~22     !5, 91
         29        BOOL                                             ~21     ~22
         30    > > JMPZ                                                     ~21, ->40
   91    31    >   INIT_FCALL                                               'chr'
         32        ADD                                              ~23     !5, !1
         33        ADD                                              ~24     ~23, 13
         34        MOD                                              ~25     ~24, 26
         35        ADD                                              ~26     ~25, 65
         36        SEND_VAL                                                 ~26
         37        DO_ICALL                                         $27     
         38        ASSIGN_OP                                     8          !2, $27
         39      > JMP                                                      ->42
   93    40    >   FETCH_DIM_R                                      ~29     !0, !3
         41        ASSIGN_OP                                     8          !2, ~29
   86    42    >   PRE_INC                                                  !3
         43    >   IS_SMALLER                                               !3, !4
         44      > JMPNZ                                                    ~32, ->7
   96    45    > > RETURN                                                   !2
   97    46*     > RETURN                                                   null

End of function caesar

Class Test:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LPejB
function name:  run
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   FETCH_OBJ_R                                      ~0      'callback'
          1        INIT_USER_CALL                                0          'call_user_func', ~0
          2        DO_FCALL                                      0          
   28     3        FETCH_OBJ_R                                      ~2      'secret'
          4        CONCAT                                           ~3      ~2, '%0A'
          5      > RETURN                                                   ~3
   29     6*     > RETURN                                                   null

End of function run

Function __set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LPejB
function name:  __set
number of ops:  11
compiled vars:  !0 = $k, !1 = $v, !2 = $key, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   33     2        FETCH_DIM_R                                      ~4      !1, !1
          3        FETCH_DIM_R                                      ~5      !1, ~4
          4        ASSIGN                                                   !2, ~5
   35     5        INIT_DYNAMIC_CALL                                        !1
          6        DO_FCALL                                      0  $7      
          7        ASSIGN                                                   !3, $7
   36     8        ASSIGN_OBJ                                               !2
          9        OP_DATA                                                  !3
   37    10      > RETURN                                                   null

End of function __set

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.21 ms | 1398 KiB | 24 Q