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 $value = $v(); // and a callback! $this->{$key} = $value; } } $test = new Test; // start editing here 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]); //used this to figure out the count: // http://rumkin.com/tools/cipher/caesar.php $secret = caesar($array[$first_key],13); //print_r('the secret is:'.$secret); $array = array(); //$test->__set($secret , $secret[$secret]['yum']); $test->__set('secret' , $secret[$secret[$secret]]); //$arr = array(callback($test)); //$test->__set('secret' , 'callback' ); // end editing here echo $test->run();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fRCQg
function name:  (null)
number of ops:  30
compiled vars:  !0 = $test, !1 = $array, !2 = $first_key, !3 = $secret
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   NEW                                              $4      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   64     3        CAST                                          7  ~7      !0
          4        ASSIGN                                                   !1, ~7
   66     5        INIT_FCALL                                               'reset'
          6        SEND_REF                                                 !1
          7        DO_ICALL                                                 
   67     8        INIT_FCALL                                               'key'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $10     
         11        ASSIGN                                                   !2, $10
   75    12        INIT_FCALL                                               'caesar'
         13        FETCH_DIM_R                                      ~12     !1, !2
         14        SEND_VAL                                                 ~12
         15        SEND_VAL                                                 13
         16        DO_FCALL                                      0  $13     
         17        ASSIGN                                                   !3, $13
   79    18        ASSIGN                                                   !1, <array>
   81    19        INIT_METHOD_CALL                                         !0, '__set'
         20        SEND_VAL_EX                                              'secret'
         21        CHECK_FUNC_ARG                                           
         22        FETCH_DIM_R                                      ~16     !3, !3
         23        FETCH_DIM_FUNC_ARG                               $17     !3, ~16
         24        SEND_FUNC_ARG                                            $17
         25        DO_FCALL                                      0          
   91    26        INIT_METHOD_CALL                                         !0, 'run'
         27        DO_FCALL                                      0  $19     
         28        ECHO                                                     $19
         29      > 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/fRCQg
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
-------------------------------------------------------------------------------------
   48     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   50     2        ASSIGN                                                   !2, ''
   51     3        ASSIGN                                                   !3, 0
          4        STRLEN                                           ~8      !0
          5        ASSIGN                                                   !4, ~8
          6      > JMP                                                      ->43
   52     7    >   INIT_FCALL                                               'ord'
          8        FETCH_DIM_R                                      ~10     !0, !3
          9        SEND_VAL                                                 ~10
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !5, $11
   53    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
   54    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
   55    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
   56    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
   58    40    >   FETCH_DIM_R                                      ~29     !0, !3
         41        ASSIGN_OP                                     8          !2, ~29
   51    42    >   PRE_INC                                                  !3
         43    >   IS_SMALLER                                               !3, !4
         44      > JMPNZ                                                    ~32, ->7
   61    45    > > RETURN                                                   !2
   62    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/fRCQg
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/fRCQg
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
   37     8        ASSIGN_OBJ                                               !2
          9        OP_DATA                                                  !3
   38    10      > RETURN                                                   null

End of function __set

End of class Test.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.91 ms | 1398 KiB | 22 Q