3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait SetterGetter { private function getFieldNameFromMethodName(string $methodName): string { $fieldName = mb_substr($methodName, 3); $fieldNameFirstChar = mb_strtolower(mb_substr($fieldName, 0, 1)); $fieldNameLastChars = mb_substr($fieldName, 1); $fieldName = $fieldNameFirstChar . $fieldNameLastChars; return $fieldName; } private function methodAllowedToBeUsedOnProperty(string $methodName, object $object, string $fieldName): bool { $property = new ReflectionProperty(get_class($object), $fieldName); $properties = $property->getAttributes(); foreach ($properties as $property) { $methods[] = $property->getName(); } return $methods; } public function __call(string $name, array $arguments) { $prefix = mb_substr($name, 0, 3); if ($prefix !== 'get' && $prefix !== 'set') { throw new SetterGetterException('Из необъявленных методов этого класса можно вызывать только геттер и сеттер.'); } $fieldName = $this->getFieldNameFromMethodName($name); if (!property_exists(get_class($object), $fieldName)) { throw new SetterGetterException('В классе ' . get_class($object) . 'не существует свойства с именем' . $fieldName); } $methods = methodAllowedToBeUsedOnProperty($name, $this, $fieldName); if (!in_array($prefix, $methods)) { throw new SetterGetterException('К этому полю нельзя обращаться через метод ' . $prefix); } if ($prefix === 'get') { return $this->$fieldName; } elseif ($prefix === 'set') { if (count($arguments) !== 1) { throw new SetterGetterException('В сеттер можно передавать только один аргумент.'); } $fieldValue = $arguments[0]; $this->$fieldName = $fieldValue; } } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oq2BZ
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E > > RETURN                                                   1

Class SetterGetter:
Function getfieldnamefrommethodname:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oq2BZ
function name:  getFieldNameFromMethodName
number of ops:  26
compiled vars:  !0 = $methodName, !1 = $fieldName, !2 = $fieldNameFirstChar, !3 = $fieldNameLastChars
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1        INIT_FCALL                                               'mb_substr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 3
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
    8     6        INIT_FCALL                                               'mb_strtolower'
          7        INIT_FCALL                                               'mb_substr'
          8        SEND_VAR                                                 !1
          9        SEND_VAL                                                 0
         10        SEND_VAL                                                 1
         11        DO_ICALL                                         $6      
         12        SEND_VAR                                                 $6
         13        DO_ICALL                                         $7      
         14        ASSIGN                                                   !2, $7
    9    15        INIT_FCALL                                               'mb_substr'
         16        SEND_VAR                                                 !1
         17        SEND_VAL                                                 1
         18        DO_ICALL                                         $9      
         19        ASSIGN                                                   !3, $9
   10    20        CONCAT                                           ~11     !2, !3
         21        ASSIGN                                                   !1, ~11
   11    22        VERIFY_RETURN_TYPE                                       !1
         23      > RETURN                                                   !1
   12    24*       VERIFY_RETURN_TYPE                                       
         25*     > RETURN                                                   null

End of function getfieldnamefrommethodname

Function methodallowedtobeusedonproperty:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/oq2BZ
function name:  methodAllowedToBeUsedOnProperty
number of ops:  24
compiled vars:  !0 = $methodName, !1 = $object, !2 = $fieldName, !3 = $property, !4 = $properties, !5 = $methods
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   16     3        NEW                                              $6      'ReflectionProperty'
          4        GET_CLASS                                        ~7      !1
          5        SEND_VAL_EX                                              ~7
          6        SEND_VAR_EX                                              !2
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !3, $6
   17     9        INIT_METHOD_CALL                                         !3, 'getAttributes'
         10        DO_FCALL                                      0  $10     
         11        ASSIGN                                                   !4, $10
   18    12      > FE_RESET_R                                       $12     !4, ->19
         13    > > FE_FETCH_R                                               $12, !3, ->19
   19    14    >   INIT_METHOD_CALL                                         !3, 'getName'
         15        DO_FCALL                                      0  $14     
         16        ASSIGN_DIM                                               !5
         17        OP_DATA                                                  $14
   18    18      > JMP                                                      ->13
         19    >   FE_FREE                                                  $12
   21    20        VERIFY_RETURN_TYPE                                       !5
         21      > RETURN                                                   !5
   22    22*       VERIFY_RETURN_TYPE                                       
         23*     > RETURN                                                   null

End of function methodallowedtobeusedonproperty

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 36
Branch analysis from position: 28
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 54
Branch analysis from position: 49
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 59
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 72
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 68
Branch analysis from position: 64
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
Branch analysis from position: 12
filename:       /in/oq2BZ
function name:  __call
number of ops:  73
compiled vars:  !0 = $name, !1 = $arguments, !2 = $prefix, !3 = $fieldName, !4 = $object, !5 = $methods, !6 = $fieldValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   26     2        INIT_FCALL                                               'mb_substr'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 0
          5        SEND_VAL                                                 3
          6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !2, $7
   28     8        IS_NOT_IDENTICAL                                 ~9      !2, 'get'
          9      > JMPZ_EX                                          ~9      ~9, ->12
         10    >   IS_NOT_IDENTICAL                                 ~10     !2, 'set'
         11        BOOL                                             ~9      ~10
         12    > > JMPZ                                                     ~9, ->17
   29    13    >   NEW                                              $11     'SetterGetterException'
         14        SEND_VAL_EX                                              '%D0%98%D0%B7+%D0%BD%D0%B5%D0%BE%D0%B1%D1%8A%D1%8F%D0%B2%D0%BB%D0%B5%D0%BD%D0%BD%D1%8B%D1%85+%D0%BC%D0%B5%D1%82%D0%BE%D0%B4%D0%BE%D0%B2+%D1%8D%D1%82%D0%BE%D0%B3%D0%BE+%D0%BA%D0%BB%D0%B0%D1%81%D1%81%D0%B0+%D0%BC%D0%BE%D0%B6%D0%BD%D0%BE+%D0%B2%D1%8B%D0%B7%D1%8B%D0%B2%D0%B0%D1%82%D1%8C+%D1%82%D0%BE%D0%BB%D1%8C%D0%BA%D0%BE+%D0%B3%D0%B5%D1%82%D1%82%D0%B5%D1%80+%D0%B8+%D1%81%D0%B5%D1%82%D1%82%D0%B5%D1%80.'
         15        DO_FCALL                                      0          
         16      > THROW                                         0          $11
   32    17    >   INIT_METHOD_CALL                                         'getFieldNameFromMethodName'
         18        SEND_VAR_EX                                              !0
         19        DO_FCALL                                      0  $13     
         20        ASSIGN                                                   !3, $13
   34    21        INIT_FCALL                                               'property_exists'
         22        GET_CLASS                                        ~15     !4
         23        SEND_VAL                                                 ~15
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $16     
         26        BOOL_NOT                                         ~17     $16
         27      > JMPZ                                                     ~17, ->36
   35    28    >   NEW                                              $18     'SetterGetterException'
         29        GET_CLASS                                        ~19     !4
         30        CONCAT                                           ~20     '%D0%92+%D0%BA%D0%BB%D0%B0%D1%81%D1%81%D0%B5+', ~19
         31        CONCAT                                           ~21     ~20, '%D0%BD%D0%B5+%D1%81%D1%83%D1%89%D0%B5%D1%81%D1%82%D0%B2%D1%83%D0%B5%D1%82+%D1%81%D0%B2%D0%BE%D0%B9%D1%81%D1%82%D0%B2%D0%B0+%D1%81+%D0%B8%D0%BC%D0%B5%D0%BD%D0%B5%D0%BC'
         32        CONCAT                                           ~22     ~21, !3
         33        SEND_VAL_EX                                              ~22
         34        DO_FCALL                                      0          
         35      > THROW                                         0          $18
   38    36    >   INIT_FCALL_BY_NAME                                       'methodAllowedToBeUsedOnProperty'
         37        SEND_VAR_EX                                              !0
         38        FETCH_THIS                                       $24     
         39        SEND_VAR_EX                                              $24
         40        SEND_VAR_EX                                              !3
         41        DO_FCALL                                      0  $25     
         42        ASSIGN                                                   !5, $25
   40    43        INIT_FCALL                                               'in_array'
         44        SEND_VAR                                                 !2
         45        SEND_VAR                                                 !5
         46        DO_ICALL                                         $27     
         47        BOOL_NOT                                         ~28     $27
         48      > JMPZ                                                     ~28, ->54
   41    49    >   NEW                                              $29     'SetterGetterException'
         50        CONCAT                                           ~30     '%D0%9A+%D1%8D%D1%82%D0%BE%D0%BC%D1%83+%D0%BF%D0%BE%D0%BB%D1%8E+%D0%BD%D0%B5%D0%BB%D1%8C%D0%B7%D1%8F+%D0%BE%D0%B1%D1%80%D0%B0%D1%89%D0%B0%D1%82%D1%8C%D1%81%D1%8F+%D1%87%D0%B5%D1%80%D0%B5%D0%B7+%D0%BC%D0%B5%D1%82%D0%BE%D0%B4+', !2
         51        SEND_VAL_EX                                              ~30
         52        DO_FCALL                                      0          
         53      > THROW                                         0          $29
   44    54    >   IS_IDENTICAL                                             !2, 'get'
         55      > JMPZ                                                     ~32, ->59
   45    56    >   FETCH_OBJ_R                                      ~33     !3
         57      > RETURN                                                   ~33
   44    58*       JMP                                                      ->72
   46    59    >   IS_IDENTICAL                                             !2, 'set'
         60      > JMPZ                                                     ~34, ->72
   47    61    >   COUNT                                            ~35     !1
         62        IS_NOT_IDENTICAL                                         ~35, 1
         63      > JMPZ                                                     ~36, ->68
   48    64    >   NEW                                              $37     'SetterGetterException'
         65        SEND_VAL_EX                                              '%D0%92+%D1%81%D0%B5%D1%82%D1%82%D0%B5%D1%80+%D0%BC%D0%BE%D0%B6%D0%BD%D0%BE+%D0%BF%D0%B5%D1%80%D0%B5%D0%B4%D0%B0%D0%B2%D0%B0%D1%82%D1%8C+%D1%82%D0%BE%D0%BB%D1%8C%D0%BA%D0%BE+%D0%BE%D0%B4%D0%B8%D0%BD+%D0%B0%D1%80%D0%B3%D1%83%D0%BC%D0%B5%D0%BD%D1%82.'
         66        DO_FCALL                                      0          
         67      > THROW                                         0          $37
   51    68    >   FETCH_DIM_R                                      ~39     !1, 0
         69        ASSIGN                                                   !6, ~39
   53    70        ASSIGN_OBJ                                               !3
         71        OP_DATA                                                  !6
   55    72    > > RETURN                                                   null

End of function __call

End of class SetterGetter.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.94 ms | 1014 KiB | 17 Q