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 echo $key;exit; $value = $v(); // and a callback! $this->{$key} = $value; } } $test = new Test; // start editing here class MyClass implements arrayaccess{ protected $array = array( 'arraykey' => 'arraykey2', 'arraykey2' => 'callback', ); public $closure; public function __construct($test){ $this->closure = function(){ echo 'nearly there! just need to reshuffle the letters now, can set secret too as its not in scope.'; }; $this->closure = $this->closure->bindTo($test); // I dont really understand what this is doing } public function __toString(){ // Object of class V could not be converted to string; return 'arraykey'; } // 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; } } $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/rTWlR
function name:  (null)
number of ops:  13
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   NEW                                              $1      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   47     3        DECLARE_CLASS                                            'myclass'
   92     4        NEW                                              $5      'MyClass'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN_OBJ                                               !0, 'callback'
          8        OP_DATA                                                  $5
   96     9        INIT_METHOD_CALL                                         !0, 'run'
         10        DO_FCALL                                      0  $7      
         11        ECHO                                                     $7
         12      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FrTWlR%3A58%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTWlR
function name:  {closure}
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   ECHO                                                     'nearly+there%21+just+need+to+reshuffle+the+letters+now%2C+can+set+secret+too+as+its+not+in+scope.'
   60     1      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FrTWlR%3A58%240

Class Test:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rTWlR
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 = 79) Position 1 = -2
filename:       /in/rTWlR
function name:  __set
number of ops:  13
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        ECHO                                                     !2
          6      > EXIT                                                     
   36     7*       INIT_DYNAMIC_CALL                                        !1
          8*       DO_FCALL                                      0  $7      
          9*       ASSIGN                                                   !3, $7
   37    10*       ASSIGN_OBJ                                               !2
         11*       OP_DATA                                                  !3
   38    12*     > RETURN                                                   null

End of function __set

End of class Test.

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

End of function __construct

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

End of function __tostring

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/rTWlR
function name:  offsetSet
number of ops:  12
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   73     2        TYPE_CHECK                                    2          !0
          3      > JMPZ                                                     ~2, ->8
   74     4    >   FETCH_OBJ_W                                      $3      'array'
          5        ASSIGN_DIM                                               $3
          6        OP_DATA                                                  !1
          7      > JMP                                                      ->11
   76     8    >   FETCH_OBJ_W                                      $5      'array'
          9        ASSIGN_DIM                                               $5, !0
         10        OP_DATA                                                  !1
   78    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/rTWlR
function name:  offsetExists
number of ops:  5
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   RECV                                             !0      
   80     1        FETCH_OBJ_IS                                     ~1      'array'
          2        ISSET_ISEMPTY_DIM_OBJ                         0  ~2      ~1, !0
          3      > RETURN                                                   ~2
   81     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/rTWlR
function name:  offsetUnset
number of ops:  4
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   RECV                                             !0      
   83     1        FETCH_OBJ_UNSET                                  $1      'array'
          2        UNSET_DIM                                                $1, !0
   84     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/rTWlR
function name:  offsetGet
number of ops:  13
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   85     0  E >   RECV                                             !0      
   86     1        CAST                                          6  ~1      !0
          2        ASSIGN                                                   !0, ~1
   87     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
   88    12*     > RETURN                                                   null

End of function offsetget

End of class MyClass.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.64 ms | 1394 KiB | 13 Q