3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait GetterAndSetter { /** * @var string */ private $setterPrefix = 'set'; /** * @var string */ private $getterPrefix = 'get'; /** * Assigns value to property by attempting to find its * setter. If no setter exists the value is casted into * appropriate type and assigned to the property directly. * * @param $key * @param $value * @return $this */ function __set($key, $value) { $expectedSetter = "{$this->setterPrefix}{$key}"; if ( method_exists($this, $expectedSetter) ) { $this->{$expectedSetter}($value); } elseif ( property_exists($this, $key) ){ $enforcedType = gettype($this->{$key}); $this->{$key} = $value; settype($this->{$key}, $enforcedType); } return $this; } /** * Invokes matching getter if defined * otherwise returns property as is. * * @param $key * @return mixed */ function __get($key) { $expectedGetter = $this->getterPrefix . $key; if ( method_exists($this, $expectedGetter) ) { return $this->{$expectedGetter}(); } return $this->{$key}; } /** * Resolves setClassProperty($val) to $obj->classProperty = $val, * casts appropriate type to value and assigns * to property * * @param $method string Name of possible setter method * @param $val mixed Value to assign to property * @return $this */ function __call($method, $val=[]) { $possibleKey = lcfirst(str_replace($this->setterPrefix, '', $method)); if ( property_exists($this, $possibleKey) ){ $enforcedType = gettype($this->{$possibleKey}); $this->{$possibleKey} = $val[0]; settype($this->{$possibleKey}, $enforcedType); } return $this; } } class AuthorizeNetCustomer { //Will call setters when available otherwise //value will be casted to the property's type //and assigned. use GetterAndSetter; private $merchantCustomerId; private $description; private $email; private $paymentProfiles = array(); private $shipToList = array(); private $customerProfileId; function __construct() { $this->merchantCustomerId = (int) $this->merchantCustomerId; $this->customerProfileId = (int) $this->customerProfileId; $this->description = (string) $this->description; $this->email = (string) $this->email; } public function setPaymentProfiles(array $val){ $this->paymentProfiles = $val; } public function setShipToList(array $val){ $this->shipToList = $val; } public function getShipToList() { return 'adasd'; } } $a = new AuthorizeNetCustomer(); $a->setEmail('cgrandos@delivery.com'); $a->merchantCustomerId = '1'; $a->setCustomerProfileId('34') ->setDescription(232323) ->setShipToList([1,2,3]); var_dump($a->email); var_dump($a->merchantCustomerId); var_dump($a->customerProfileId); var_dump($a->description); var_dump($a->shipToList);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sUGTf
function name:  (null)
number of ops:  39
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   78     0  E >   DECLARE_CLASS                                            'authorizenetcustomer'
  113     1        NEW                                              $1      'AuthorizeNetCustomer'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $1
  114     4        INIT_METHOD_CALL                                         !0, 'setEmail'
          5        SEND_VAL_EX                                              'cgrandos%40delivery.com'
          6        DO_FCALL                                      0          
  115     7        ASSIGN_OBJ                                               !0, 'merchantCustomerId'
          8        OP_DATA                                                  '1'
  116     9        INIT_METHOD_CALL                                         !0, 'setCustomerProfileId'
         10        SEND_VAL_EX                                              '34'
         11        DO_FCALL                                      0  $6      
  117    12        INIT_METHOD_CALL                                         $6, 'setDescription'
         13        SEND_VAL_EX                                              232323
         14        DO_FCALL                                      0  $7      
  118    15        INIT_METHOD_CALL                                         $7, 'setShipToList'
         16        SEND_VAL_EX                                              <array>
         17        DO_FCALL                                      0          
  120    18        INIT_FCALL                                               'var_dump'
         19        FETCH_OBJ_R                                      ~9      !0, 'email'
         20        SEND_VAL                                                 ~9
         21        DO_ICALL                                                 
  121    22        INIT_FCALL                                               'var_dump'
         23        FETCH_OBJ_R                                      ~11     !0, 'merchantCustomerId'
         24        SEND_VAL                                                 ~11
         25        DO_ICALL                                                 
  122    26        INIT_FCALL                                               'var_dump'
         27        FETCH_OBJ_R                                      ~13     !0, 'customerProfileId'
         28        SEND_VAL                                                 ~13
         29        DO_ICALL                                                 
  123    30        INIT_FCALL                                               'var_dump'
         31        FETCH_OBJ_R                                      ~15     !0, 'description'
         32        SEND_VAL                                                 ~15
         33        DO_ICALL                                                 
  124    34        INIT_FCALL                                               'var_dump'
         35        FETCH_OBJ_R                                      ~17     !0, 'shipToList'
         36        SEND_VAL                                                 ~17
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

Class GetterAndSetter:
Function __set:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 32
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename:       /in/sUGTf
function name:  __set
number of ops:  35
compiled vars:  !0 = $key, !1 = $value, !2 = $expectedSetter, !3 = $enforcedType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   26     2        FETCH_OBJ_R                                      ~4      'setterPrefix'
          3        NOP                                                      
          4        FAST_CONCAT                                      ~5      ~4, !0
          5        ASSIGN                                                   !2, ~5
   28     6        INIT_FCALL                                               'method_exists'
          7        FETCH_THIS                                       ~7      
          8        SEND_VAL                                                 ~7
          9        SEND_VAR                                                 !2
         10        DO_ICALL                                         $8      
         11      > JMPZ                                                     $8, ->16
   29    12    >   INIT_METHOD_CALL                                         !2
         13        SEND_VAR_EX                                              !1
         14        DO_FCALL                                      0          
         15      > JMP                                                      ->32
   31    16    >   INIT_FCALL                                               'property_exists'
         17        FETCH_THIS                                       ~10     
         18        SEND_VAL                                                 ~10
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                         $11     
         21      > JMPZ                                                     $11, ->32
   32    22    >   FETCH_OBJ_R                                      ~12     !0
         23        GET_TYPE                                         ~13     ~12
         24        ASSIGN                                                   !3, ~13
   33    25        ASSIGN_OBJ                                               !0
         26        OP_DATA                                                  !1
   34    27        INIT_FCALL                                               'settype'
         28        FETCH_OBJ_W                                      $16     !0
         29        SEND_REF                                                 $16
         30        SEND_VAR                                                 !3
         31        DO_ICALL                                                 
   37    32    >   FETCH_THIS                                       ~18     
         33      > RETURN                                                   ~18
   38    34*     > RETURN                                                   null

End of function __set

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sUGTf
function name:  __get
number of ops:  16
compiled vars:  !0 = $key, !1 = $expectedGetter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        FETCH_OBJ_R                                      ~2      'getterPrefix'
          2        CONCAT                                           ~3      ~2, !0
          3        ASSIGN                                                   !1, ~3
   50     4        INIT_FCALL                                               'method_exists'
          5        FETCH_THIS                                       ~5      
          6        SEND_VAL                                                 ~5
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $6      
          9      > JMPZ                                                     $6, ->13
   51    10    >   INIT_METHOD_CALL                                         !1
         11        DO_FCALL                                      0  $7      
         12      > RETURN                                                   $7
   54    13    >   FETCH_OBJ_R                                      ~8      !0
         14      > RETURN                                                   ~8
   55    15*     > RETURN                                                   null

End of function __get

Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 29
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/sUGTf
function name:  __call
number of ops:  32
compiled vars:  !0 = $method, !1 = $val, !2 = $possibleKey, !3 = $enforcedType
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
   67     2        INIT_FCALL                                               'lcfirst'
          3        INIT_FCALL                                               'str_replace'
          4        FETCH_OBJ_R                                      ~4      'setterPrefix'
          5        SEND_VAL                                                 ~4
          6        SEND_VAL                                                 ''
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9        SEND_VAR                                                 $5
         10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !2, $6
   69    12        INIT_FCALL                                               'property_exists'
         13        FETCH_THIS                                       ~8      
         14        SEND_VAL                                                 ~8
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $9      
         17      > JMPZ                                                     $9, ->29
   70    18    >   FETCH_OBJ_R                                      ~10     !2
         19        GET_TYPE                                         ~11     ~10
         20        ASSIGN                                                   !3, ~11
   71    21        FETCH_DIM_R                                      ~14     !1, 0
         22        ASSIGN_OBJ                                               !2
         23        OP_DATA                                                  ~14
   72    24        INIT_FCALL                                               'settype'
         25        FETCH_OBJ_W                                      $15     !2
         26        SEND_REF                                                 $15
         27        SEND_VAR                                                 !3
         28        DO_ICALL                                                 
   75    29    >   FETCH_THIS                                       ~17     
         30      > RETURN                                                   ~17
   76    31*     > RETURN                                                   null

End of function __call

End of class GetterAndSetter.

Class AuthorizeNetCustomer:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sUGTf
function name:  __construct
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   93     0  E >   FETCH_OBJ_R                                      ~1      'merchantCustomerId'
          1        CAST                                          4  ~2      ~1
          2        ASSIGN_OBJ                                               'merchantCustomerId'
          3        OP_DATA                                                  ~2
   94     4        FETCH_OBJ_R                                      ~4      'customerProfileId'
          5        CAST                                          4  ~5      ~4
          6        ASSIGN_OBJ                                               'customerProfileId'
          7        OP_DATA                                                  ~5
   95     8        FETCH_OBJ_R                                      ~7      'description'
          9        CAST                                          6  ~8      ~7
         10        ASSIGN_OBJ                                               'description'
         11        OP_DATA                                                  ~8
   96    12        FETCH_OBJ_R                                      ~10     'email'
         13        CAST                                          6  ~11     ~10
         14        ASSIGN_OBJ                                               'email'
         15        OP_DATA                                                  ~11
   97    16      > RETURN                                                   null

End of function __construct

Function setpaymentprofiles:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sUGTf
function name:  setPaymentProfiles
number of ops:  4
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   99     0  E >   RECV                                             !0      
  100     1        ASSIGN_OBJ                                               'paymentProfiles'
          2        OP_DATA                                                  !0
  101     3      > RETURN                                                   null

End of function setpaymentprofiles

Function setshiptolist:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sUGTf
function name:  setShipToList
number of ops:  4
compiled vars:  !0 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  103     0  E >   RECV                                             !0      
  104     1        ASSIGN_OBJ                                               'shipToList'
          2        OP_DATA                                                  !0
  105     3      > RETURN                                                   null

End of function setshiptolist

Function getshiptolist:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/sUGTf
function name:  getShipToList
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  108     0  E > > RETURN                                                   'adasd'
  109     1*     > RETURN                                                   null

End of function getshiptolist

End of class AuthorizeNetCustomer.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.69 ms | 1412 KiB | 25 Q