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 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('Nyy lbhe Onfr ner orybat gb hf.'); $newLetters = array(); foreach ($letters as $letter){ $ascii = ord($letter); $newAscii = $ascii; $lowercaseA = 97; $uppercaseA = 65; $pivot = (ctype_upper($letter)) ? $uppercaseA : $lowercaseA ; $pivot += SHIFT; if($letter != " "){ if ($ascii >= $pivot){ $newAscii = ($ascii - SHIFT); }else{ $newAscii = ($ascii + 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, though I don't like variables with arrays named $array. 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; } // class 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/oq6hD
function name:  (null)
number of ops:  17
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        INIT_FCALL                                               'define'
          4        SEND_VAL                                                 'SHIFT'
          5        SEND_VAL                                                 13
          6        DO_ICALL                                                 
   48     7        DECLARE_CLASS                                            'myclass'
  125     8        NEW                                              $6      'MyClass'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0          
         11        ASSIGN_OBJ                                               !0, 'callback'
         12        OP_DATA                                                  $6
  129    13        INIT_METHOD_CALL                                         !0, 'run'
         14        DO_FCALL                                      0  $8      
         15        ECHO                                                     $8
         16      > RETURN                                                   1

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

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

Class Test:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oq6hD
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/oq6hD
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/oq6hD
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/oq6hD
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/oq6hD
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/oq6hD
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/oq6hD
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%2Foq6hD%3A76%240'
          2        ASSIGN_OBJ                                               'closure'
  101     3        OP_DATA                                                  ~2
  102     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
  104    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/oq6hD
function name:  __invoke
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  114     0  E >   FETCH_OBJ_R                                      ~0      'closure'
          1      > RETURN                                                   ~0
  115     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/oq6hD
function name:  __toString
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  120     0  E > > RETURN                                                   'firstKey'
  121     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:
149.12 ms | 1412 KiB | 25 Q