3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); interface HasId { public string $id { get; set; } public string $displayedId { get; } } abstract class Super implements HasId { public protected(set) string $displayedId; function __construct( public string $id { set (string $value) { $this->id = $value; $this->displayedId = $value; } }, ) {} } class Foo extends Super { public protected(set) string $displayedId { get => '#' . $this->displayedId; set (string $value) => $this->displayedId = mb_strtoupper($value); } } class Bar extends Super { public string $displayedId; } class Baz { public function display(HasId $object): void { echo $object->displayedId . PHP_EOL; } public function update(HasId $object, string $id): void{ $object->id = $id; $this->display($object); } } $foo = new Foo(id: 'FOO'); $bar = new Bar(id: 'BAR'); $baz = new Baz(); $baz->display($foo); $baz->update($foo, 'foo'); $baz->display($bar); $baz->update($bar, 'bar'); $bar->displayedId = 'TEST'; $baz->display($bar); // Following statement is forbidden $foo->displayedId = 'TEST';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5IECI
function name:  (null)
number of ops:  38
compiled vars:  !0 = $foo, !1 = $bar, !2 = $baz
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   DECLARE_CLASS                                                'super'
   23     1        DECLARE_CLASS                                                'foo', 'super'
   30     2        DECLARE_CLASS                                                'bar', 'super'
   46     3        NEW                                                  $3      'Foo'
          4        SEND_VAL_EX                                                  'FOO', 'id'
          5        CHECK_UNDEF_ARGS                                             
          6        DO_FCALL                                          1          
          7        ASSIGN                                                       !0, $3
   47     8        NEW                                                  $6      'Bar'
          9        SEND_VAL_EX                                                  'BAR', 'id'
         10        CHECK_UNDEF_ARGS                                             
         11        DO_FCALL                                          1          
         12        ASSIGN                                                       !1, $6
   48    13        NEW                                                  $9      'Baz'
         14        DO_FCALL                                          0          
         15        ASSIGN                                                       !2, $9
   50    16        INIT_METHOD_CALL                                             !2, 'display'
         17        SEND_VAR_EX                                                  !0
         18        DO_FCALL                                          0          
   51    19        INIT_METHOD_CALL                                             !2, 'update'
         20        SEND_VAR_EX                                                  !0
         21        SEND_VAL_EX                                                  'foo'
         22        DO_FCALL                                          0          
   53    23        INIT_METHOD_CALL                                             !2, 'display'
         24        SEND_VAR_EX                                                  !1
         25        DO_FCALL                                          0          
   54    26        INIT_METHOD_CALL                                             !2, 'update'
         27        SEND_VAR_EX                                                  !1
         28        SEND_VAL_EX                                                  'bar'
         29        DO_FCALL                                          0          
   56    30        ASSIGN_OBJ                                                   !1, 'displayedId'
         31        OP_DATA                                                      'TEST'
   57    32        INIT_METHOD_CALL                                             !2, 'display'
         33        SEND_VAR_EX                                                  !1
         34        DO_FCALL                                          0          
   60    35        ASSIGN_OBJ                                                   !0, 'displayedId'
         36        OP_DATA                                                      'TEST'
         37      > RETURN                                                       1

Class HasId: [no user functions]
Property id:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5IECI
function name:  $id::get
number of ops:  2
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   VERIFY_RETURN_TYPE                                           
          1      > RETURN                                                       null

End of property id:

Property id:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5IECI
function name:  $id::set
number of ops:  2
compiled vars:  !0 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
          0  E >   RECV                                                 !0      
          1      > RETURN                                                       null

End of property id:

Property displayedId:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5IECI
function name:  $displayedId::get
number of ops:  2
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   VERIFY_RETURN_TYPE                                           
          1      > RETURN                                                       null

End of property displayedId:

Property displayedId:
End of property displayedId:

Class Super:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5IECI
function name:  __construct
number of ops:  4
compiled vars:  !0 = $id
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        ASSIGN_OBJ                                                   'id'
          2        OP_DATA                                                      !0
   20     3      > RETURN                                                       null

End of function __construct

End of class Super.

Property id:
End of property id:

Property id:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5IECI
function name:  $id::set
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
   16     1        ASSIGN_OBJ                                                   'id'
          2        OP_DATA                                                      !0
   17     3        ASSIGN_OBJ                                                   'displayedId'
          4        OP_DATA                                                      !0
   18     5      > RETURN                                                       null

End of property id:

Class Foo: [no user functions]
Property displayedId:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5IECI
function name:  $displayedId::get
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   25     0  E >   FETCH_OBJ_R                                          ~0      'displayedId'
          1        CONCAT                                               ~1      '%23', ~0
          2        VERIFY_RETURN_TYPE                                           ~1
          3      > RETURN                                                       ~1
          4*       VERIFY_RETURN_TYPE                                           
          5*     > RETURN                                                       null

End of property displayedId:

Property displayedId:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5IECI
function name:  $displayedId::set
number of ops:  9
compiled vars:  !0 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   RECV                                                 !0      
          1        INIT_FCALL                                                   'mb_strtoupper'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $3      
          4        ASSIGN_OBJ                                           ~2      'displayedId'
          5        OP_DATA                                                      $3
          6        ASSIGN_OBJ                                                   'displayedId'
          7        OP_DATA                                                      ~2
          8      > RETURN                                                       null

End of property displayedId:

Class Bar: [no user functions]
Class Baz:
Function display:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5IECI
function name:  display
number of ops:  5
compiled vars:  !0 = $object
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   35     0  E >   RECV                                                 !0      
   37     1        FETCH_OBJ_R                                          ~1      !0, 'displayedId'
          2        CONCAT                                               ~2      ~1, '%0A'
          3        ECHO                                                         ~2
   38     4      > RETURN                                                       null

End of function display

Function update:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5IECI
function name:  update
number of ops:  8
compiled vars:  !0 = $object, !1 = $id
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   40     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   41     2        ASSIGN_OBJ                                                   !0, 'id'
          3        OP_DATA                                                      !1
   42     4        INIT_METHOD_CALL                                             'display'
          5        SEND_VAR_EX                                                  !0
          6        DO_FCALL                                          0          
   43     7      > RETURN                                                       null

End of function update

End of class Baz.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
156.28 ms | 1110 KiB | 14 Q