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 something that became available in 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 $value = $v(); // and a callback! $this->{$key} = $value; } } $test = new Test; // start editing here $testArr = (array) $test; var_dump($testArr); echo $testArr['Testsecret']; class Obj implements ArrayAccess { private $t; public function __construct($t) { $this->t = $t; return; } public function offsetSet($offset, $value) { return; } public function offsetExists($offset) { return; } public function offsetUnset($offset) { return; } public function offsetGet($offset) { return 'callback'; } public function __invoke() { $tObj = $this->t; return (function($tObj) { print_r($t); }); } } $obj = new Obj($test); $test->x = $obj; // end editing here echo $test->run();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oH5BS
function name:  (null)
number of ops:  21
compiled vars:  !0 = $test, !1 = $testArr, !2 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   NEW                                              $3      'Test'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   32     3        CAST                                          7  ~6      !0
          4        ASSIGN                                                   !1, ~6
   34     5        INIT_FCALL                                               'var_dump'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
   35     8        FETCH_DIM_R                                      ~9      !1, 'Testsecret'
          9        ECHO                                                     ~9
   37    10        DECLARE_CLASS                                            'obj'
   57    11        NEW                                              $10     'Obj'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
         14        ASSIGN                                                   !2, $10
   59    15        ASSIGN_OBJ                                               !0, 'x'
         16        OP_DATA                                                  !2
   62    17        INIT_METHOD_CALL                                         !0, 'run'
         18        DO_FCALL                                      0  $14     
         19        ECHO                                                     $14
         20      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FoH5BS%3A53%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oH5BS
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $tObj, !1 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   RECV                                             !0      
          1        INIT_FCALL                                               'print_r'
          2        SEND_VAR                                                 !1
          3        DO_ICALL                                                 
          4      > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FoH5BS%3A53%240

Class Test:
Function run:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oH5BS
function name:  run
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   FETCH_OBJ_R                                      ~0      'callback'
          1        INIT_USER_CALL                                0          'call_user_func', ~0
          2        DO_FCALL                                      0          
   21     3        FETCH_OBJ_R                                      ~2      'secret'
          4        CONCAT                                           ~3      ~2, '%0A'
          5      > RETURN                                                   ~3
   22     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/oH5BS
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
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        FETCH_DIM_R                                      ~4      !1, !1
          3        FETCH_DIM_R                                      ~5      !1, ~4
          4        ASSIGN                                                   !2, ~5
   26     5        INIT_DYNAMIC_CALL                                        !1
          6        DO_FCALL                                      0  $7      
          7        ASSIGN                                                   !3, $7
   27     8        ASSIGN_OBJ                                               !2
          9        OP_DATA                                                  !3
   28    10      > RETURN                                                   null

End of function __set

End of class Test.

Class Obj:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oH5BS
function name:  __construct
number of ops:  5
compiled vars:  !0 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   40     1        ASSIGN_OBJ                                               't'
          2        OP_DATA                                                  !0
   41     3      > RETURN                                                   null
   42     4*     > RETURN                                                   null

End of function __construct

Function offsetset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oH5BS
function name:  offsetSet
number of ops:  4
compiled vars:  !0 = $offset, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2      > RETURN                                                   null
          3*     > 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/oH5BS
function name:  offsetExists
number of ops:  3
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1      > RETURN                                                   null
          2*     > 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/oH5BS
function name:  offsetUnset
number of ops:  3
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1      > RETURN                                                   null
          2*     > RETURN                                                   null

End of function offsetunset

Function offsetget:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oH5BS
function name:  offsetGet
number of ops:  3
compiled vars:  !0 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1      > RETURN                                                   'callback'
   49     2*     > RETURN                                                   null

End of function offsetget

Function __invoke:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oH5BS
function name:  __invoke
number of ops:  5
compiled vars:  !0 = $tObj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   FETCH_OBJ_R                                      ~1      't'
          1        ASSIGN                                                   !0, ~1
   53     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FoH5BS%3A53%240'
          3      > RETURN                                                   ~3
   54     4*     > RETURN                                                   null

End of function __invoke

End of class Obj.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.72 ms | 1404 KiB | 17 Q