3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Auto{ function auto($args) { $reflectionClass = new ReflectionClass($this); $reflectionMethod = $reflectionClass->getMethod ('__construct'); $parameters = $reflectionMethod->getParameters(); $count = 0; foreach($parameters as $parameter) { $paramName = $parameter->getName(); if ($reflectionClass->hasProperty($paramName) == true) { $this->{$paramName} = $args[$count]; } $count++; } } } class TestClass { use Auto; private $foo; private $bar; function __construct($foo, $bar) { $args = func_get_args(); $this->auto($args); } function getFoo() { return $this->foo; } function getBar() { return $this->bar; } } $test = new TestClass("Hello", "World!"); echo $test->getFoo().' '.$test->getBar();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LQ5IM
function name:  (null)
number of ops:  14
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   DECLARE_CLASS                                            'testclass'
   62     1        NEW                                              $1      'TestClass'
          2        SEND_VAL_EX                                              'Hello'
          3        SEND_VAL_EX                                              'World%21'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
   64     6        INIT_METHOD_CALL                                         !0, 'getFoo'
          7        DO_FCALL                                      0  $4      
          8        CONCAT                                           ~5      $4, '+'
          9        INIT_METHOD_CALL                                         !0, 'getBar'
         10        DO_FCALL                                      0  $6      
         11        CONCAT                                           ~7      ~5, $6
         12        ECHO                                                     ~7
         13      > RETURN                                                   1

Class Auto:
Function auto:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 29
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 29
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 27
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/LQ5IM
function name:  auto
number of ops:  31
compiled vars:  !0 = $args, !1 = $reflectionClass, !2 = $reflectionMethod, !3 = $parameters, !4 = $count, !5 = $parameter, !6 = $paramName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        NEW                                              $7      'ReflectionClass'
          2        FETCH_THIS                                       $8      
          3        SEND_VAR_EX                                              $8
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $7
   13     6        INIT_METHOD_CALL                                         !1, 'getMethod'
          7        SEND_VAL_EX                                              '__construct'
          8        DO_FCALL                                      0  $11     
          9        ASSIGN                                                   !2, $11
   15    10        INIT_METHOD_CALL                                         !2, 'getParameters'
         11        DO_FCALL                                      0  $13     
         12        ASSIGN                                                   !3, $13
   17    13        ASSIGN                                                   !4, 0
   19    14      > FE_RESET_R                                       $16     !3, ->29
         15    > > FE_FETCH_R                                               $16, !5, ->29
   21    16    >   INIT_METHOD_CALL                                         !5, 'getName'
         17        DO_FCALL                                      0  $17     
         18        ASSIGN                                                   !6, $17
   23    19        INIT_METHOD_CALL                                         !1, 'hasProperty'
         20        SEND_VAR_EX                                              !6
         21        DO_FCALL                                      0  $19     
         22        BOOL                                             ~20     $19
         23      > JMPZ                                                     ~20, ->27
   24    24    >   FETCH_DIM_R                                      ~22     !0, !4
         25        ASSIGN_OBJ                                               !6
         26        OP_DATA                                                  ~22
   27    27    >   PRE_INC                                                  !4
   19    28      > JMP                                                      ->15
         29    >   FE_FREE                                                  $16
   30    30      > RETURN                                                   null

End of function auto

End of class Auto.

Class TestClass:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LQ5IM
function name:  __construct
number of ops:  8
compiled vars:  !0 = $foo, !1 = $bar, !2 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   46     2        FUNC_GET_ARGS                                    ~3      
          3        ASSIGN                                                   !2, ~3
   48     4        INIT_METHOD_CALL                                         'auto'
          5        SEND_VAR_EX                                              !2
          6        DO_FCALL                                      0          
   49     7      > RETURN                                                   null

End of function __construct

Function getfoo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LQ5IM
function name:  getFoo
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   FETCH_OBJ_R                                      ~0      'foo'
          1      > RETURN                                                   ~0
   53     2*     > RETURN                                                   null

End of function getfoo

Function getbar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LQ5IM
function name:  getBar
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   FETCH_OBJ_R                                      ~0      'bar'
          1      > RETURN                                                   ~0
   57     2*     > RETURN                                                   null

End of function getbar

End of class TestClass.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.62 ms | 1399 KiB | 13 Q