3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Challenge 1: Read and write to 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 $this->testy = $key; $value = $v(); // and a callback! $this->{$key} = $value; } } $test = new Test; // start editing here class Intercept { public function getKey($test) { $array = (array) $test; reset($array); $first_key = key($array); print_r($array[$first_key]); //$v = array(); //$v[$first_key] = 'blah'; //$blah = $v[$first_key]; $blah= array(); $blah[($first_key[$first_key])] = 'dobee'; $test->__set($array[$first_key] , $blah[$first_key] ); /* foreach($array as $k => $v) { print_r($k); print_r($v); } */ } } $intercept = new Intercept; $intercept->getKey($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/7ApBu
function name:  (null)
number of ops:  13
compiled vars:  !0 = $test, !1 = $intercept
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   NEW                                              $2      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   81     3        NEW                                              $5      'Intercept'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   82     6        INIT_METHOD_CALL                                         !1, 'getKey'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
   87     9        INIT_METHOD_CALL                                         !0, 'run'
         10        DO_FCALL                                      0  $9      
         11        ECHO                                                     $9
         12      > RETURN                                                   1

Class Test:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7ApBu
function name:  run
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   FETCH_OBJ_R                                      ~0      'callback'
          1        INIT_USER_CALL                                0          'call_user_func', ~0
          2        DO_FCALL                                      0          
   31     3        FETCH_OBJ_R                                      ~2      'secret'
          4        CONCAT                                           ~3      ~2, '%0A'
          5      > RETURN                                                   ~3
   32     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/7ApBu
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
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   36     2        FETCH_DIM_R                                      ~4      !1, !1
          3        FETCH_DIM_R                                      ~5      !1, ~4
          4        ASSIGN                                                   !2, ~5
   37     5        ASSIGN_OBJ                                               'testy'
          6        OP_DATA                                                  !2
   38     7        INIT_DYNAMIC_CALL                                        !1
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !3, $8
   39    10        ASSIGN_OBJ                                               !2
         11        OP_DATA                                                  !3
   40    12      > RETURN                                                   null

End of function __set

End of class Test.

Class Intercept:
Function getkey:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7ApBu
function name:  getKey
number of ops:  27
compiled vars:  !0 = $test, !1 = $array, !2 = $first_key, !3 = $blah
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
   56     1        CAST                                          7  ~4      !0
          2        ASSIGN                                                   !1, ~4
   58     3        INIT_FCALL                                               'reset'
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
   59     6        INIT_FCALL                                               'key'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !2, $7
   61    10        INIT_FCALL                                               'print_r'
         11        FETCH_DIM_R                                      ~9      !1, !2
         12        SEND_VAL                                                 ~9
         13        DO_ICALL                                                 
   66    14        ASSIGN                                                   !3, <array>
   67    15        FETCH_DIM_R                                      ~12     !2, !2
         16        ASSIGN_DIM                                               !3, ~12
         17        OP_DATA                                                  'dobee'
   69    18        INIT_METHOD_CALL                                         !0, '__set'
         19        CHECK_FUNC_ARG                                           
         20        FETCH_DIM_FUNC_ARG                               $14     !1, !2
         21        SEND_FUNC_ARG                                            $14
         22        CHECK_FUNC_ARG                                           
         23        FETCH_DIM_FUNC_ARG                               $15     !3, !2
         24        SEND_FUNC_ARG                                            $15
         25        DO_FCALL                                      0          
   78    26      > RETURN                                                   null

End of function getkey

End of class Intercept.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.27 ms | 1392 KiB | 19 Q