3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Immutable { public function __construct(/** @psalm-readonly */ public stdClass $neverChange) {} public function mutate(): void { $this->neverChange->foo = 1; } } class DoOtherStuff { public function doStuff(Immutable $immutable): void { $immutable->mutate(); } } $data = new stdClass; $data->foo = 0; $immutable = new Immutable($data); /* ... */ if ($immutable->neverChange->foo === 0) { /* ... */ (new DoOtherStuff())->doStuff($immutable); /* Here I would assume, that my immutable object still holds the not change value stdClass::foo = 0 but it got mutated to stdClass::foo = 1 */ } echo "Does this code actually run without any syntax errors? " . ($immutable->neverChange->foo ? 'Me definetly think so...' : 'No, some internet rando was smarter than me rapid typing some example which everybody did understand anyways');
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/IfpNO
function name:  (null)
number of ops:  27
compiled vars:  !0 = $data, !1 = $immutable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   NEW                                              $2      'stdClass'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   13     3        ASSIGN_OBJ                                               !0, 'foo'
          4        OP_DATA                                                  0
   15     5        NEW                                              $6      'Immutable'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $6
   18     9        FETCH_OBJ_R                                      ~9      !1, 'neverChange'
         10        FETCH_OBJ_R                                      ~10     ~9, 'foo'
         11        IS_IDENTICAL                                             ~10, 0
         12      > JMPZ                                                     ~11, ->18
   20    13    >   NEW                                              $12     'DoOtherStuff'
         14        DO_FCALL                                      0          
         15        INIT_METHOD_CALL                                         $12, 'doStuff'
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0          
   27    18    >   FETCH_OBJ_R                                      ~15     !1, 'neverChange'
         19        FETCH_OBJ_R                                      ~16     ~15, 'foo'
         20      > JMPZ                                                     ~16, ->23
         21    >   QM_ASSIGN                                        ~17     'Me+definetly+think+so...'
         22      > JMP                                                      ->24
         23    >   QM_ASSIGN                                        ~17     'No%2C+some+internet+rando+was+smarter+than+me+rapid+typing+some+example+which+everybody+did+understand+anyways'
         24    >   CONCAT                                           ~18     'Does+this+code+actually+run+without+any+syntax+errors%3F+', ~17
         25        ECHO                                                     ~18
         26      > RETURN                                                   1

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

End of function __construct

Function mutate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IfpNO
function name:  mutate
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   FETCH_OBJ_W                                      $0      'neverChange'
          1        ASSIGN_OBJ                                               $0, 'foo'
          2        OP_DATA                                                  1
          3      > RETURN                                                   null

End of function mutate

End of class Immutable.

Class DoOtherStuff:
Function dostuff:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IfpNO
function name:  doStuff
number of ops:  4
compiled vars:  !0 = $immutable
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
          1        INIT_METHOD_CALL                                         !0, 'mutate'
          2        DO_FCALL                                      0          
          3      > RETURN                                                   null

End of function dostuff

End of class DoOtherStuff.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
122.13 ms | 1438 KiB | 13 Q