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; public $testy; final public function run() { call_user_func($this->callback); die($this->testy); 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[0] = 'dobee'; //$test->__set($array[$first_key] , $blah ); /* foreach($array as $k => $v) { print_r($k); print_r($v); } */ } } $intercept = new Intercept; $intercept->getKey($test); // end editing here //echo $test->run(); $test->run();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Zkbt8
function name:  (null)
number of ops:  12
compiled vars:  !0 = $test, !1 = $intercept
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   NEW                                              $2      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   86     3        NEW                                              $5      'Intercept'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   87     6        INIT_METHOD_CALL                                         !1, 'getKey'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
   93     9        INIT_METHOD_CALL                                         !0, 'run'
         10        DO_FCALL                                      0          
         11      > RETURN                                                   1

Class Test:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/Zkbt8
function name:  run
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   FETCH_OBJ_R                                      ~0      'callback'
          1        INIT_USER_CALL                                0          'call_user_func', ~0
          2        DO_FCALL                                      0          
   33     3        FETCH_OBJ_R                                      ~2      'testy'
          4      > EXIT                                                     ~2
   35     5*       FETCH_OBJ_R                                      ~3      'secret'
          6*       CONCAT                                           ~4      ~3, '%0A'
          7*       RETURN                                                   ~4
   36     8*     > 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/Zkbt8
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
-------------------------------------------------------------------------------------
   38     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   40     2        FETCH_DIM_R                                      ~4      !1, !1
          3        FETCH_DIM_R                                      ~5      !1, ~4
          4        ASSIGN                                                   !2, ~5
   42     5        ASSIGN_OBJ                                               'testy'
          6        OP_DATA                                                  !2
   43     7        INIT_DYNAMIC_CALL                                        !1
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                                   !3, $8
   44    10        ASSIGN_OBJ                                               !2
         11        OP_DATA                                                  !3
   45    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/Zkbt8
function name:  getKey
number of ops:  18
compiled vars:  !0 = $test, !1 = $array, !2 = $first_key, !3 = $blah
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   RECV                                             !0      
   61     1        CAST                                          7  ~4      !0
          2        ASSIGN                                                   !1, ~4
   63     3        INIT_FCALL                                               'reset'
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
   64     6        INIT_FCALL                                               'key'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !2, $7
   66    10        INIT_FCALL                                               'print_r'
         11        FETCH_DIM_R                                      ~9      !1, !2
         12        SEND_VAL                                                 ~9
         13        DO_ICALL                                                 
   71    14        ASSIGN                                                   !3, <array>
   72    15        ASSIGN_DIM                                               !3, 0
         16        OP_DATA                                                  'dobee'
   83    17      > RETURN                                                   null

End of function getkey

End of class Intercept.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.28 ms | 1392 KiB | 19 Q