3v4l.org

run code in 500+ 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 = 25, Position 2 = 33
Branch analysis from position: 25
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 48
Branch analysis from position: 43
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 53
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 66
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 62
Branch analysis from position: 58
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
Branch analysis from position: 12
filename:       /in/oq2BZ
function name:  __call
number of ops:  67
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        GET_CLASS                                            ~15     !4
         22        FRAMELESS_ICALL_2                property_exists      ~16     ~15, !3
         23        BOOL_NOT                                             ~17     ~16
         24      > JMPZ                                                         ~17, ->33
   35    25    >   NEW                                                  $18     'SetterGetterException'
         26        GET_CLASS                                            ~19     !4
         27        CONCAT                                               ~20     '%D0%92+%D0%BA%D0%BB%D0%B0%D1%81%D1%81%D0%B5+', ~19
         28        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'
         29        CONCAT                                               ~22     ~21, !3
         30        SEND_VAL_EX                                                  ~22
         31        DO_FCALL                                          0          
         32      > THROW                                             0          $18
   38    33    >   INIT_FCALL_BY_NAME                                           'methodAllowedToBeUsedOnProperty'
         34        SEND_VAR_EX                                                  !0
         35        FETCH_THIS                                           $24     
         36        SEND_VAR_EX                                                  $24
         37        SEND_VAR_EX                                                  !3
         38        DO_FCALL                                          0  $25     
         39        ASSIGN                                                       !5, $25
   40    40        FRAMELESS_ICALL_2                in_array            ~27     !2, !5
         41        BOOL_NOT                                             ~28     ~27
         42      > JMPZ                                                         ~28, ->48
   41    43    >   NEW                                                  $29     'SetterGetterException'
         44        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
         45        SEND_VAL_EX                                                  ~30
         46        DO_FCALL                                          0          
         47      > THROW                                             0          $29
   44    48    >   IS_IDENTICAL                                                 !2, 'get'
         49      > JMPZ                                                         ~32, ->53
   45    50    >   FETCH_OBJ_R                                          ~33     !3
         51      > RETURN                                                       ~33
   44    52*       JMP                                                          ->66
   46    53    >   IS_IDENTICAL                                                 !2, 'set'
         54      > JMPZ                                                         ~34, ->66
   47    55    >   COUNT                                                ~35     !1
         56        IS_NOT_IDENTICAL                                             ~35, 1
         57      > JMPZ                                                         ~36, ->62
   48    58    >   NEW                                                  $37     'SetterGetterException'
         59        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.'
         60        DO_FCALL                                          0          
         61      > THROW                                             0          $37
   51    62    >   FETCH_DIM_R                                          ~39     !1, 0
         63        ASSIGN                                                       !6, ~39
   53    64        ASSIGN_OBJ                                                   !3
         65        OP_DATA                                                      !6
   55    66    > > RETURN                                                       null

End of function __call

End of class SetterGetter.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.7 ms | 1592 KiB | 15 Q