3v4l.org

run code in 300+ PHP versions simultaneously
<?php class TestSampleClass { } class ParameterReflection extends ReflectionParameter { protected $isFromMethod = false; public function getDeclaringClass() { $phpReflection = parent::getDeclaringClass(); $zendReflection = new ReflectionClass($phpReflection->getName()); unset($phpReflection); return $zendReflection; } public function getClass() { $phpReflection = parent::getClass(); if ($phpReflection == null) { return null; } $zendReflection = new ClassReflection($phpReflection->getName()); unset($phpReflection); return $zendReflection; } public function getDeclaringFunction($reflectionClass = null) { $phpReflection = parent::getDeclaringFunction(); if ($phpReflection instanceof ReflectionMethod) { $zendReflection = new ReflectionMethod($this->getDeclaringClass()->getName(), $phpReflection->getName()); } else { $zendReflection = new ReflectionFunction($phpReflection->getName()); } unset($phpReflection); return $zendReflection; } public function getType() { $type = null; $checkDefault = true; if ($this->isArray()) { $type = 'array'; } elseif (($class = $this->getClass()) instanceof ReflectionClass) { $type = $class->getName(); } /*elseif ($docBlock = $this->getDeclaringFunction()->getDocBlock()) { $params = $docBlock->getTags('param'); if (isset($params[$this->getPosition()])) { $type = $params[$this->getPosition()]->getType(); $checkDefault = false; } }*/ var_dump($this->isDefaultValueAvailable()); if ($this->isDefaultValueAvailable() && $checkDefault) { if ($type === null) { $value = $this->getDefaultValue(); var_dump($value); $type = strtolower(gettype($value)); switch ($type) { case 'boolean' : $type = 'bool'; break; case 'integer' : $type = 'int'; break; } } else { if ($this->getDefaultValue() === null) { $type .= '|null'; } } } return $type; } } class TestSampleClass5 { /** * @param int $one Description for one * @param int Description for two * @param string $three Description for three * which spans multiple lines */ public function doSomething($one, $two = 2, $three = 'three', $empty = null, $string = 'somestring', $null = null, $int = 1, $bool = true, array $array, array $arrayOrNull = null, TestSampleClass $class, TestSampleClass $classOrNull = null) { return 'mixedValue'; } } $tests = array( // array('one', 'int'), // array('two', 'int'), // array('three', 'string'), array('empty', null), array('string', 'string'), array('null', 'null'), array('int', 'int'), array('bool', 'bool'), array('array', 'array'), array('arrayOrNull','array|null'), array('class', 'ZendTest\Code\Reflection\TestAsset\TestSampleClass'), array('classOrNull','ZendTest\Code\Reflection\TestAsset\TestSampleClass|null'), ); foreach($tests as $test) { $param = new ParameterReflection(array('TestSampleClass5', 'doSomething'), $test[0]); var_dump($param->getType()); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 16
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/6KBbp
function name:  (null)
number of ops:  18
compiled vars:  !0 = $tests, !1 = $test, !2 = $param
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   95     0  E >   ASSIGN                                                   !0, <array>
  110     1      > FE_RESET_R                                       $4      !0, ->16
          2    > > FE_FETCH_R                                               $4, !1, ->16
  112     3    >   NEW                                              $5      'ParameterReflection'
          4        SEND_VAL_EX                                              <array>
          5        CHECK_FUNC_ARG                                           
          6        FETCH_DIM_FUNC_ARG                               $6      !1, 0
          7        SEND_FUNC_ARG                                            $6
          8        DO_FCALL                                      0          
          9        ASSIGN                                                   !2, $5
  114    10        INIT_FCALL                                               'var_dump'
         11        INIT_METHOD_CALL                                         !2, 'getType'
         12        DO_FCALL                                      0  $9      
         13        SEND_VAR                                                 $9
         14        DO_ICALL                                                 
  110    15      > JMP                                                      ->2
         16    >   FE_FREE                                                  $4
  115    17      > RETURN                                                   1

Class TestSampleClass: [no user functions]
Class ParameterReflection:
Function getdeclaringclass:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6KBbp
function name:  getDeclaringClass
number of ops:  12
compiled vars:  !0 = $phpReflection, !1 = $zendReflection
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   INIT_STATIC_METHOD_CALL                                  'getDeclaringClass'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   12     3        NEW                                              $4      'ReflectionClass'
          4        INIT_METHOD_CALL                                         !0, 'getName'
          5        DO_FCALL                                      0  $5      
          6        SEND_VAR_NO_REF_EX                                       $5
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $4
   13     9        UNSET_CV                                                 !0
   15    10      > RETURN                                                   !1
   16    11*     > RETURN                                                   null

End of function getdeclaringclass

Function getclass:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6KBbp
function name:  getClass
number of ops:  15
compiled vars:  !0 = $phpReflection, !1 = $zendReflection
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   INIT_STATIC_METHOD_CALL                                  'getClass'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN                                                   !0, $2
   20     3        IS_EQUAL                                                 !0, null
          4      > JMPZ                                                     ~4, ->6
   21     5    > > RETURN                                                   null
   23     6    >   NEW                                              $5      'ClassReflection'
          7        INIT_METHOD_CALL                                         !0, 'getName'
          8        DO_FCALL                                      0  $6      
          9        SEND_VAR_NO_REF_EX                                       $6
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !1, $5
   24    12        UNSET_CV                                                 !0
   26    13      > RETURN                                                   !1
   27    14*     > RETURN                                                   null

End of function getclass

Function getdeclaringfunction:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6KBbp
function name:  getDeclaringFunction
number of ops:  27
compiled vars:  !0 = $reflectionClass, !1 = $phpReflection, !2 = $zendReflection
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   RECV_INIT                                        !0      null
   30     1        INIT_STATIC_METHOD_CALL                                  'getDeclaringFunction'
          2        DO_FCALL                                      0  $3      
          3        ASSIGN                                                   !1, $3
   31     4        INSTANCEOF                                               !1, 'ReflectionMethod'
          5      > JMPZ                                                     ~5, ->18
   32     6    >   NEW                                              $6      'ReflectionMethod'
          7        INIT_METHOD_CALL                                         'getDeclaringClass'
          8        DO_FCALL                                      0  $7      
          9        INIT_METHOD_CALL                                         $7, 'getName'
         10        DO_FCALL                                      0  $8      
         11        SEND_VAR_NO_REF_EX                                       $8
         12        INIT_METHOD_CALL                                         !1, 'getName'
         13        DO_FCALL                                      0  $9      
         14        SEND_VAR_NO_REF_EX                                       $9
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !2, $6
         17      > JMP                                                      ->24
   34    18    >   NEW                                              $12     'ReflectionFunction'
         19        INIT_METHOD_CALL                                         !1, 'getName'
         20        DO_FCALL                                      0  $13     
         21        SEND_VAR_NO_REF_EX                                       $13
         22        DO_FCALL                                      0          
         23        ASSIGN                                                   !2, $12
   36    24    >   UNSET_CV                                                 !1
   38    25      > RETURN                                                   !2
   39    26*     > RETURN                                                   null

End of function getdeclaringfunction

Function gettype:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 54
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 49
Branch analysis from position: 27
4 jumps found. (Code = 188) Position 1 = 44, Position 2 = 46, Position 3 = 48, Position 4 = 39
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 48
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 43, Position 2 = 46
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
Branch analysis from position: 46
Branch analysis from position: 44
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 54
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
Branch analysis from position: 54
Branch analysis from position: 24
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
Branch analysis from position: 24
Branch analysis from position: 15
filename:       /in/6KBbp
function name:  getType
number of ops:  56
compiled vars:  !0 = $type, !1 = $checkDefault, !2 = $class, !3 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   42     0  E >   ASSIGN                                                   !0, null
   44     1        ASSIGN                                                   !1, <true>
   46     2        INIT_METHOD_CALL                                         'isArray'
          3        DO_FCALL                                      0  $6      
          4      > JMPZ                                                     $6, ->7
   47     5    >   ASSIGN                                                   !0, 'array'
          6      > JMP                                                      ->15
   48     7    >   INIT_METHOD_CALL                                         'getClass'
          8        DO_FCALL                                      0  $8      
          9        ASSIGN                                           ~9      !2, $8
         10        INSTANCEOF                                               ~9, 'ReflectionClass'
         11      > JMPZ                                                     ~10, ->15
   49    12    >   INIT_METHOD_CALL                                         !2, 'getName'
         13        DO_FCALL                                      0  $11     
         14        ASSIGN                                                   !0, $11
   59    15    >   INIT_FCALL                                               'var_dump'
         16        INIT_METHOD_CALL                                         'isDefaultValueAvailable'
         17        DO_FCALL                                      0  $13     
         18        SEND_VAR                                                 $13
         19        DO_ICALL                                                 
   60    20        INIT_METHOD_CALL                                         'isDefaultValueAvailable'
         21        DO_FCALL                                      0  $15     
         22      > JMPZ_EX                                          ~16     $15, ->24
         23    >   BOOL                                             ~16     !1
         24    > > JMPZ                                                     ~16, ->54
   61    25    >   TYPE_CHECK                                    2          !0
         26      > JMPZ                                                     ~17, ->49
   62    27    >   INIT_METHOD_CALL                                         'getDefaultValue'
         28        DO_FCALL                                      0  $18     
         29        ASSIGN                                                   !3, $18
   64    30        INIT_FCALL                                               'var_dump'
         31        SEND_VAR                                                 !3
         32        DO_ICALL                                                 
   65    33        INIT_FCALL                                               'strtolower'
         34        GET_TYPE                                         ~21     !3
         35        SEND_VAL                                                 ~21
         36        DO_ICALL                                         $22     
         37        ASSIGN                                                   !0, $22
   67    38      > SWITCH_STRING                                            !0, [ 'boolean':->44, 'integer':->46, ], ->48
   68    39    >   IS_EQUAL                                                 !0, 'boolean'
         40      > JMPNZ                                                    ~24, ->44
   69    41    >   IS_EQUAL                                                 !0, 'integer'
         42      > JMPNZ                                                    ~24, ->46
         43    > > JMP                                                      ->48
   68    44    >   ASSIGN                                                   !0, 'bool'
         45      > JMP                                                      ->48
   69    46    >   ASSIGN                                                   !0, 'int'
         47      > JMP                                                      ->48
         48    > > JMP                                                      ->54
   72    49    >   INIT_METHOD_CALL                                         'getDefaultValue'
         50        DO_FCALL                                      0  $27     
         51        TYPE_CHECK                                    2          $27
         52      > JMPZ                                                     ~28, ->54
   73    53    >   ASSIGN_OP                                     8          !0, '%7Cnull'
   78    54    > > RETURN                                                   !0
   79    55*     > RETURN                                                   null

End of function gettype

End of class ParameterReflection.

Class TestSampleClass5:
Function dosomething:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6KBbp
function name:  doSomething
number of ops:  14
compiled vars:  !0 = $one, !1 = $two, !2 = $three, !3 = $empty, !4 = $string, !5 = $null, !6 = $int, !7 = $bool, !8 = $array, !9 = $arrayOrNull, !10 = $class, !11 = $classOrNull
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   89     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
          2        RECV_INIT                                        !2      'three'
          3        RECV_INIT                                        !3      null
          4        RECV_INIT                                        !4      'somestring'
          5        RECV_INIT                                        !5      null
          6        RECV_INIT                                        !6      1
          7        RECV_INIT                                        !7      <true>
          8        RECV                                             !8      
          9        RECV_INIT                                        !9      null
         10        RECV                                             !10     
         11        RECV_INIT                                        !11     null
   91    12      > RETURN                                                   'mixedValue'
   92    13*     > RETURN                                                   null

End of function dosomething

End of class TestSampleClass5.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146 ms | 1428 KiB | 17 Q