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 4. No redefining $test 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 <-- its not an array its an object being used as if it was an array $value = $v(); // and a callback! <-- its not a callback, its an object being called like it is a callback $this->{$key} = $value; } } $test = new Test; // start editing here class MyClass implements arrayaccess{ const SHIFT = 13; // array access stuff below was copied and pasted from http://www.php.net/manual/en/class.arrayaccess.php public function offsetSet($offset, $value) { if (is_null($offset)) { $this->array[] = $value; } else { $this->array[$offset] = $value; } } public function offsetExists($offset) { return isset($this->array[$offset]); } public function offsetUnset($offset) { unset($this->array[$offset]); } public function offsetGet($offset) { $offset = (string) $offset; return isset($this->array[$offset]) ? $this->array[$offset] : null; } // My stuff public $closure; public function __construct($test) { $this->closure = function() { // this is where we can reshuffle the letters, will be execuated on line 28 $letters = str_split($this->secret); $newLetters = array(); foreach ($letters as $letter) { $ascii = ord($letter); $newAscii = $ascii; $pivot = (ctype_upper($letter)) ? ord('A') : ord('a') + $this->SHIFT ; if($letter != " "){ if ($ascii >= $pivot){ $newAscii = ($ascii - $this->SHIFT); }else{ $newAscii = ($ascii + $this->SHIFT); } } $newLetters[] = chr($newAscii); } $this->secret = join($newLetters); }; $this->closure = $this->closure->bindTo($test, $test); } // $key on line 34 needs to be 'callback', $array is used the arrayaccess functions public $array = array( 'firstKey' => 'secondKey', 'secondKey' => 'callback', ); // and value on line 35 needs to be my closure function to do stuff with the string public function __invoke(){ return $this->closure; } // MyClass needs to be accessible as a string to set the array stuff rolling public function __toString(){ // Object of class MyClass could not be converted to string; return 'firstKey'; } } $test->callback = new MyClass($test); // end editing here echo $test->run();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lFGgb
function name:  (null)
number of ops:  13
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   NEW                                              $1      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   46     3        DECLARE_CLASS                                            'myclass'
  124     4        NEW                                              $5      'MyClass'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN_OBJ                                               !0, 'callback'
          8        OP_DATA                                                  $5
  128     9        INIT_METHOD_CALL                                         !0, 'run'
         10        DO_FCALL                                      0  $7      
         11        ECHO                                                     $7
         12      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FlFGgb%3A76%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 44
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 44
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 38
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 38
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 38
Branch analysis from position: 27
Branch analysis from position: 38
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/lFGgb
function name:  {closure}
number of ops:  52
compiled vars:  !0 = $letters, !1 = $newLetters, !2 = $letter, !3 = $ascii, !4 = $newAscii, !5 = $pivot
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   INIT_FCALL                                               'str_split'
          1        FETCH_THIS                                       $6      
          2        FETCH_OBJ_R                                      ~7      $6, 'secret'
          3        SEND_VAL                                                 ~7
          4        DO_ICALL                                         $8      
          5        ASSIGN                                                   !0, $8
   81     6        ASSIGN                                                   !1, <array>
   83     7      > FE_RESET_R                                       $11     !0, ->44
          8    > > FE_FETCH_R                                               $11, !2, ->44
   85     9    >   INIT_FCALL                                               'ord'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $12     
         12        ASSIGN                                                   !3, $12
   86    13        ASSIGN                                                   !4, !3
   87    14        INIT_FCALL                                               'ctype_upper'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $15     
         17      > JMPZ                                                     $15, ->20
         18    >   QM_ASSIGN                                        ~16     65
         19      > JMP                                                      ->24
         20    >   FETCH_THIS                                       $17     
         21        FETCH_OBJ_R                                      ~18     $17, 'SHIFT'
         22        ADD                                              ~19     97, ~18
         23        QM_ASSIGN                                        ~16     ~19
         24    >   ASSIGN                                                   !5, ~16
   88    25        IS_NOT_EQUAL                                             !2, '+'
         26      > JMPZ                                                     ~21, ->38
   89    27    >   IS_SMALLER_OR_EQUAL                                      !5, !3
         28      > JMPZ                                                     ~22, ->34
   90    29    >   FETCH_THIS                                       $23     
         30        FETCH_OBJ_R                                      ~24     $23, 'SHIFT'
         31        SUB                                              ~25     !3, ~24
         32        ASSIGN                                                   !4, ~25
         33      > JMP                                                      ->38
   92    34    >   FETCH_THIS                                       $27     
         35        FETCH_OBJ_R                                      ~28     $27, 'SHIFT'
         36        ADD                                              ~29     !3, ~28
         37        ASSIGN                                                   !4, ~29
   95    38    >   INIT_FCALL                                               'chr'
         39        SEND_VAR                                                 !4
         40        DO_ICALL                                         $32     
         41        ASSIGN_DIM                                               !1
         42        OP_DATA                                                  $32
   83    43      > JMP                                                      ->8
         44    >   FE_FREE                                                  $11
   98    45        FETCH_THIS                                       $33     
         46        INIT_FCALL                                               'join'
         47        SEND_VAR                                                 !1
         48        DO_ICALL                                         $35     
         49        ASSIGN_OBJ                                               $33, 'secret'
         50        OP_DATA                                                  $35
  100    51      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FlFGgb%3A76%240

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

Class MyClass:
Function offsetset:
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 = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lFGgb
function name:  offsetSet
number of ops:  12
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   53     2        TYPE_CHECK                                    2          !0
          3      > JMPZ                                                     ~2, ->8
   54     4    >   FETCH_OBJ_W                                      $3      'array'
          5        ASSIGN_DIM                                               $3
          6        OP_DATA                                                  !1
          7      > JMP                                                      ->11
   56     8    >   FETCH_OBJ_W                                      $5      'array'
          9        ASSIGN_DIM                                               $5, !0
         10        OP_DATA                                                  !1
   58    11    > > RETURN                                                   null

End of function offsetset

Function offsetexists:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lFGgb
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   RECV                                             !0      
   60     1        FETCH_OBJ_IS                                     ~1      'array'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
   61     4*     > RETURN                                                   null

End of function offsetexists

Function offsetunset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lFGgb
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
   63     1        FETCH_OBJ_UNSET                                  $1      'array'
          2        UNSET_DIM                                                $1, !0
   64     3      > RETURN                                                   null

End of function offsetunset

Function offsetget:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lFGgb
function name:  offsetGet
number of ops:  13
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   RECV                                             !0      
   66     1        CAST                                          6  ~1      !0
          2        ASSIGN                                                   !0, ~1
   67     3        FETCH_OBJ_IS                                     ~3      'array'
          4        ISSET_ISEMPTY_DIM_OBJ                         0          ~3, !0
          5      > JMPZ                                                     ~4, ->10
          6    >   FETCH_OBJ_R                                      ~5      'array'
          7        FETCH_DIM_R                                      ~6      ~5, !0
          8        QM_ASSIGN                                        ~7      ~6
          9      > JMP                                                      ->11
         10    >   QM_ASSIGN                                        ~7      null
         11    > > RETURN                                                   ~7
   68    12*     > RETURN                                                   null

End of function offsetget

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lFGgb
function name:  __construct
number of ops:  12
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   74     0  E >   RECV                                             !0      
   76     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FlFGgb%3A76%240'
          2        ASSIGN_OBJ                                               'closure'
  100     3        OP_DATA                                                  ~2
  101     4        FETCH_OBJ_R                                      ~4      'closure'
          5        INIT_METHOD_CALL                                         ~4, 'bindTo'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0  $5      
          9        ASSIGN_OBJ                                               'closure'
         10        OP_DATA                                                  $5
  103    11      > RETURN                                                   null

End of function __construct

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

End of function __invoke

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lFGgb
function name:  __toString
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  119     0  E > > RETURN                                                   'firstKey'
  120     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function __tostring

End of class MyClass.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.68 ms | 1412 KiB | 23 Q