3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public static $has_many = "Post"; public function has_many($a){ return 'hola'; } function get_relationship($model) { $class = new ReflectionClass($this); $staticProperties = $class->getStaticProperties(); foreach($staticProperties as $propertyName => $value) { if(preg_match('/^(has_many|age)$/', $propertyName) && $value == $model) { return $this->{$propertyName}($model); } } } function __get($name) { if(substr($name, -strlen('_set')) === '_set') { $model = ucwords(substr($name, 4)); return $this->get_relationship($model); } } } echo substr('post_set', -strlen('_set')); $foo = new Foo; echo $foo->post_set; ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nFEke
function name:  (null)
number of ops:  11
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   INIT_FCALL                                               'substr'
          1        SEND_VAL                                                 'post_set'
          2        SEND_VAL                                                 -4
          3        DO_ICALL                                         $1      
          4        ECHO                                                     $1
   40     5        NEW                                              $2      'Foo'
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !0, $2
   41     8        FETCH_OBJ_R                                      ~5      !0, 'post_set'
          9        ECHO                                                     ~5
   44    10      > RETURN                                                   1

Class Foo:
Function has_many:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nFEke
function name:  has_many
number of ops:  3
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1      > RETURN                                                   'hola'
    8     2*     > RETURN                                                   null

End of function has_many

Function get_relationship:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 26
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 26
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 19
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/nFEke
function name:  get_relationship
number of ops:  28
compiled vars:  !0 = $model, !1 = $class, !2 = $staticProperties, !3 = $value, !4 = $propertyName
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        NEW                                              $5      'ReflectionClass'
          2        FETCH_THIS                                       $6      
          3        SEND_VAR_EX                                              $6
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   14     6        INIT_METHOD_CALL                                         !1, 'getStaticProperties'
          7        DO_FCALL                                      0  $9      
          8        ASSIGN                                                   !2, $9
   16     9      > FE_RESET_R                                       $11     !2, ->26
         10    > > FE_FETCH_R                                       ~12     $11, !3, ->26
         11    >   ASSIGN                                                   !4, ~12
   17    12        INIT_FCALL                                               'preg_match'
         13        SEND_VAL                                                 '%2F%5E%28has_many%7Cage%29%24%2F'
         14        SEND_VAR                                                 !4
         15        DO_ICALL                                         $14     
         16      > JMPZ_EX                                          ~15     $14, ->19
         17    >   IS_EQUAL                                         ~16     !3, !0
         18        BOOL                                             ~15     ~16
         19    > > JMPZ                                                     ~15, ->25
   18    20    >   INIT_METHOD_CALL                                         !4
         21        SEND_VAR_EX                                              !0
         22        DO_FCALL                                      0  $17     
         23        FE_FREE                                                  $11
         24      > RETURN                                                   $17
   16    25    > > JMP                                                      ->10
         26    >   FE_FREE                                                  $11
   22    27      > RETURN                                                   null

End of function get_relationship

Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 19
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nFEke
function name:  __get
number of ops:  20
compiled vars:  !0 = $name, !1 = $model
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        INIT_FCALL                                               'substr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 -4
          4        DO_ICALL                                         $2      
          5        IS_IDENTICAL                                             $2, '_set'
          6      > JMPZ                                                     ~3, ->19
   27     7    >   INIT_FCALL                                               'ucwords'
          8        INIT_FCALL                                               'substr'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 4
         11        DO_ICALL                                         $4      
         12        SEND_VAR                                                 $4
         13        DO_ICALL                                         $5      
         14        ASSIGN                                                   !1, $5
   28    15        INIT_METHOD_CALL                                         'get_relationship'
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0  $7      
         18      > RETURN                                                   $7
   30    19    > > RETURN                                                   null

End of function __get

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.17 ms | 1400 KiB | 19 Q