3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait LazyGetSet { public function __call($method, $args) { if ((0 === strpos($method, 'get')) && ($ptyName = $this->getLazyPropertyName($method))) { return $this->lazyGet($ptyName, $args); } if ((0 === strpos($method, 'set')) && ($ptyName = $this->getLazyPropertyName($method))) { return $this->lazySet($ptyName, $args); } } private function getLazyPropertyName($method) { $ptyName = lcfirst(substr($method, 3)); if (property_exists($this, $ptyName)) { return $ptyName; } } private function lazyGet($ptyName) { return $this->{$ptyName}; } private function lazySet($ptyName, $args) { $this->{$ptyName} = $args[0]; return $this; } } class MyClass { use LazyGetSet; private $name; } echo (new MyClass())->setName(123)->getName();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ppCW9
function name:  (null)
number of ops:  10
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   DECLARE_CLASS                                            'myclass'
   47     1        NEW                                              $0      'MyClass'
          2        DO_FCALL                                      0          
          3        INIT_METHOD_CALL                                         $0, 'setName'
          4        SEND_VAL_EX                                              123
          5        DO_FCALL                                      0  $2      
          6        INIT_METHOD_CALL                                         $2, 'getName'
          7        DO_FCALL                                      0  $3      
          8        ECHO                                                     $3
          9      > RETURN                                                   1

Class LazyGetSet:
Function __call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 30
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 13
filename:       /in/ppCW9
function name:  __call
number of ops:  37
compiled vars:  !0 = $method, !1 = $args, !2 = $ptyName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        INIT_FCALL                                               'strpos'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 'get'
          5        DO_ICALL                                         $3      
          6        IS_IDENTICAL                                     ~4      $3, 0
          7      > JMPZ_EX                                          ~4      ~4, ->13
          8    >   INIT_METHOD_CALL                                         'getLazyPropertyName'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $5      
         11        ASSIGN                                           ~6      !2, $5
         12        BOOL                                             ~4      ~6
         13    > > JMPZ                                                     ~4, ->19
    9    14    >   INIT_METHOD_CALL                                         'lazyGet'
         15        SEND_VAR_EX                                              !2
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0  $7      
         18      > RETURN                                                   $7
   12    19    >   INIT_FCALL                                               'strpos'
         20        SEND_VAR                                                 !0
         21        SEND_VAL                                                 'set'
         22        DO_ICALL                                         $8      
         23        IS_IDENTICAL                                     ~9      $8, 0
         24      > JMPZ_EX                                          ~9      ~9, ->30
         25    >   INIT_METHOD_CALL                                         'getLazyPropertyName'
         26        SEND_VAR_EX                                              !0
         27        DO_FCALL                                      0  $10     
         28        ASSIGN                                           ~11     !2, $10
         29        BOOL                                             ~9      ~11
         30    > > JMPZ                                                     ~9, ->36
   13    31    >   INIT_METHOD_CALL                                         'lazySet'
         32        SEND_VAR_EX                                              !2
         33        SEND_VAR_EX                                              !1
         34        DO_FCALL                                      0  $12     
         35      > RETURN                                                   $12
   15    36    > > RETURN                                                   null

End of function __call

Function getlazypropertyname:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ppCW9
function name:  getLazyPropertyName
number of ops:  17
compiled vars:  !0 = $method, !1 = $ptyName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        INIT_FCALL                                               'lcfirst'
          2        INIT_FCALL                                               'substr'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 3
          5        DO_ICALL                                         $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                         $3      
          8        ASSIGN                                                   !1, $3
   20     9        INIT_FCALL                                               'property_exists'
         10        FETCH_THIS                                       ~5      
         11        SEND_VAL                                                 ~5
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $6      
         14      > JMPZ                                                     $6, ->16
   21    15    > > RETURN                                                   !1
   23    16    > > RETURN                                                   null

End of function getlazypropertyname

Function lazyget:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ppCW9
function name:  lazyGet
number of ops:  4
compiled vars:  !0 = $ptyName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1        FETCH_OBJ_R                                      ~1      !0
          2      > RETURN                                                   ~1
   28     3*     > RETURN                                                   null

End of function lazyget

Function lazyset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ppCW9
function name:  lazySet
number of ops:  8
compiled vars:  !0 = $ptyName, !1 = $args
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   32     2        FETCH_DIM_R                                      ~3      !1, 0
          3        ASSIGN_OBJ                                               !0
          4        OP_DATA                                                  ~3
   33     5        FETCH_THIS                                       ~4      
          6      > RETURN                                                   ~4
   34     7*     > RETURN                                                   null

End of function lazyset

End of class LazyGetSet.

Class MyClass: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.01 ms | 1404 KiB | 21 Q