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 <-- object needs to act like an array $value = $v(); // and a callback! <-- object needs to act like a callback $this->{$key} = $value; } } $test = new Test; // start editing here DEFINE('SHIFT', 13); class MyClass implements arrayaccess{ // 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') + SHIFT ; if($letter != " "){ if ($ascii >= $pivot){ $newAscii = ($ascii - SHIFT); }else{ $newAscii = ($ascii + SHIFT); } } $letter = chr($newAscii); } $this->secret = join($letters); }; $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/0QBRP
function name:  (null)
number of ops:  17
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   NEW                                              $1      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   45     3        INIT_FCALL                                               'define'
          4        SEND_VAL                                                 'SHIFT'
          5        SEND_VAL                                                 13
          6        DO_ICALL                                                 
   47     7        DECLARE_CLASS                                            'myclass'
  123     8        NEW                                              $6      'MyClass'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
         11        ASSIGN_OBJ                                               !0, 'callback'
         12        OP_DATA                                                  $6
  127    13        INIT_METHOD_CALL                                         !0, 'run'
         14        DO_FCALL                                      0  $8      
         15        ECHO                                                     $8
         16      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F0QBRP%3A75%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 8, Position 2 = 40
Branch analysis from position: 8
2 jumps found. (Code = 126) Position 1 = 9, Position 2 = 40
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 = 23
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 35
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 35
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 35
Branch analysis from position: 26
Branch analysis from position: 35
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/0QBRP
function name:  {closure}
number of ops:  48
compiled vars:  !0 = $letters, !1 = $newLetters, !2 = $letter, !3 = $ascii, !4 = $newAscii, !5 = $pivot
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     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
   80     6        ASSIGN                                                   !1, <array>
   82     7      > FE_RESET_RW                                      $11     !0, ->40
          8    > > FE_FETCH_RW                                              $11, !2, ->40
   84     9    >   INIT_FCALL                                               'ord'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $12     
         12        ASSIGN                                                   !3, $12
   85    13        ASSIGN                                                   !4, !3
   86    14        INIT_FCALL                                               'ctype_upper'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $15     
         17      > JMPZ                                                     $15, ->20
         18    >   QM_ASSIGN                                        ~16     65
         19      > JMP                                                      ->23
         20    >   FETCH_CONSTANT                                   ~17     'SHIFT'
         21        ADD                                              ~18     97, ~17
         22        QM_ASSIGN                                        ~16     ~18
         23    >   ASSIGN                                                   !5, ~16
   87    24        IS_NOT_EQUAL                                             !2, '+'
         25      > JMPZ                                                     ~20, ->35
   88    26    >   IS_SMALLER_OR_EQUAL                                      !5, !3
         27      > JMPZ                                                     ~21, ->32
   89    28    >   FETCH_CONSTANT                                   ~22     'SHIFT'
         29        SUB                                              ~23     !3, ~22
         30        ASSIGN                                                   !4, ~23
         31      > JMP                                                      ->35
   91    32    >   FETCH_CONSTANT                                   ~25     'SHIFT'
         33        ADD                                              ~26     !3, ~25
         34        ASSIGN                                                   !4, ~26
   94    35    >   INIT_FCALL                                               'chr'
         36        SEND_VAR                                                 !4
         37        DO_ICALL                                         $28     
         38        ASSIGN                                                   !2, $28
   82    39      > JMP                                                      ->8
         40    >   FE_FREE                                                  $11
   97    41        FETCH_THIS                                       $30     
         42        INIT_FCALL                                               'join'
         43        SEND_VAR                                                 !0
         44        DO_ICALL                                         $32     
         45        ASSIGN_OBJ                                               $30, 'secret'
         46        OP_DATA                                                  $32
   99    47      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F0QBRP%3A75%240

Class Test:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0QBRP
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/0QBRP
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/0QBRP
function name:  offsetSet
number of ops:  12
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   52     2        TYPE_CHECK                                    2          !0
          3      > JMPZ                                                     ~2, ->8
   53     4    >   FETCH_OBJ_W                                      $3      'array'
          5        ASSIGN_DIM                                               $3
          6        OP_DATA                                                  !1
          7      > JMP                                                      ->11
   55     8    >   FETCH_OBJ_W                                      $5      'array'
          9        ASSIGN_DIM                                               $5, !0
         10        OP_DATA                                                  !1
   57    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/0QBRP
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
   59     1        FETCH_OBJ_IS                                     ~1      'array'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
   60     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/0QBRP
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   61     0  E >   RECV                                             !0      
   62     1        FETCH_OBJ_UNSET                                  $1      'array'
          2        UNSET_DIM                                                $1, !0
   63     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/0QBRP
function name:  offsetGet
number of ops:  13
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   RECV                                             !0      
   65     1        CAST                                          6  ~1      !0
          2        ASSIGN                                                   !0, ~1
   66     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
   67    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/0QBRP
function name:  __construct
number of ops:  12
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   73     0  E >   RECV                                             !0      
   75     1        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F0QBRP%3A75%240'
          2        ASSIGN_OBJ                                               'closure'
   99     3        OP_DATA                                                  ~2
  100     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
  102    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/0QBRP
function name:  __invoke
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  112     0  E >   FETCH_OBJ_R                                      ~0      'closure'
          1      > RETURN                                                   ~0
  113     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/0QBRP
function name:  __toString
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  118     0  E > > RETURN                                                   'firstKey'
  119     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:
154.25 ms | 1412 KiB | 25 Q