3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PrivacyViolator { public function callPrivateMethod($object, $method, array $args = array()) { if (!is_object($object)) { throw new \InvalidArgumentException('The $object param must be object'); } $className = get_class($object); $method = new \ReflectionMethod($className, $method); $method->setAccessible(true); return $method->invokeArgs($object, $args); } } class MyClass { private function hello($name) { return 'Hello ' . $name; } } $myObject = new MyClass(); $privacyViolator = new PrivacyViolator(); $result = $privacyViolator->callPrivateMethod($myObject, 'hello', array('World')); echo $result; assert('Hello World' === $result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qOcSR
function name:  (null)
number of ops:  20
compiled vars:  !0 = $myObject, !1 = $privacyViolator, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   NEW                                              $3      'MyClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $3
   29     3        NEW                                              $6      'PrivacyViolator'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $6
   31     6        INIT_METHOD_CALL                                         !1, 'callPrivateMethod'
          7        SEND_VAR_EX                                              !0
          8        SEND_VAL_EX                                              'hello'
          9        SEND_VAL_EX                                              <array>
         10        DO_FCALL                                      0  $9      
         11        ASSIGN                                                   !2, $9
   33    12        ECHO                                                     !2
   34    13        ASSERT_CHECK                                             
         14        INIT_FCALL                                               'assert'
         15        IS_IDENTICAL                                     ~11     !2, 'Hello+World'
         16        SEND_VAL                                                 ~11
         17        SEND_VAL                                                 'assert%28%27Hello+World%27+%3D%3D%3D+%24result%29'
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

Class PrivacyViolator:
Function callprivatemethod:
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 = 108) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qOcSR
function name:  callPrivateMethod
number of ops:  26
compiled vars:  !0 = $object, !1 = $method, !2 = $args, !3 = $className
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <array>
    7     3        TYPE_CHECK                                  256  ~4      !0
          4        BOOL_NOT                                         ~5      ~4
          5      > JMPZ                                                     ~5, ->10
    8     6    >   NEW                                              $6      'InvalidArgumentException'
          7        SEND_VAL_EX                                              'The+%24object+param+must+be+object'
          8        DO_FCALL                                      0          
          9      > THROW                                         0          $6
   11    10    >   GET_CLASS                                        ~8      !0
         11        ASSIGN                                                   !3, ~8
   13    12        NEW                                              $10     'ReflectionMethod'
         13        SEND_VAR_EX                                              !3
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !1, $10
   14    17        INIT_METHOD_CALL                                         !1, 'setAccessible'
         18        SEND_VAL_EX                                              <true>
         19        DO_FCALL                                      0          
   16    20        INIT_METHOD_CALL                                         !1, 'invokeArgs'
         21        SEND_VAR_EX                                              !0
         22        SEND_VAR_EX                                              !2
         23        DO_FCALL                                      0  $14     
         24      > RETURN                                                   $14
   17    25*     > RETURN                                                   null

End of function callprivatemethod

End of class PrivacyViolator.

Class MyClass:
Function hello:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qOcSR
function name:  hello
number of ops:  4
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
   24     1        CONCAT                                           ~1      'Hello+', !0
          2      > RETURN                                                   ~1
   25     3*     > RETURN                                                   null

End of function hello

End of class MyClass.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.64 ms | 1400 KiB | 15 Q