3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Coalescing { protected $attributes = [ 'attribute1' => 'value1', ]; public function __get($name) { print "GET\n"; if (array_key_exists($name, $this->attributes)) { return $this->attributes[$name]; } trigger_error("Property $name does not exist"); return null; } } $coal = new Coalescing(); var_dump($coal->attribute1 ?? 'default'); //GET //string(6) "value1" var_dump($coal->attribute2 ?? 'default'); //GET // It should dump 'default' here. Instead, the error of __get() is triggered var_dump(isset($coal->attribute2) ? $coal->atribute2 : 'default'); //That should be the normal behaviour
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 21
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VUCFF
function name:  (null)
number of ops:  25
compiled vars:  !0 = $coal
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   21     0  E >   NEW                                                  $1      'Coalescing'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $1
   23     3        INIT_FCALL                                                   'var_dump'
          4        FETCH_OBJ_IS                                         ~4      !0, 'attribute1'
          5        COALESCE                                             ~5      ~4
          6        QM_ASSIGN                                            ~5      'default'
          7        SEND_VAL                                                     ~5
          8        DO_ICALL                                                     
   27     9        INIT_FCALL                                                   'var_dump'
         10        FETCH_OBJ_IS                                         ~7      !0, 'attribute2'
         11        COALESCE                                             ~8      ~7
         12        QM_ASSIGN                                            ~8      'default'
         13        SEND_VAL                                                     ~8
         14        DO_ICALL                                                     
   31    15        INIT_FCALL                                                   'var_dump'
         16        ISSET_ISEMPTY_PROP_OBJ                                       !0, 'attribute2'
         17      > JMPZ                                                         ~10, ->21
         18    >   FETCH_OBJ_R                                          ~11     !0, 'atribute2'
         19        QM_ASSIGN                                            ~12     ~11
         20      > JMP                                                          ->22
         21    >   QM_ASSIGN                                            ~12     'default'
         22    >   SEND_VAL                                                     ~12
         23        DO_ICALL                                                     
   32    24      > RETURN                                                       1

Class Coalescing:
Function __get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VUCFF
function name:  __get
number of ops:  16
compiled vars:  !0 = $name
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
   10     1        ECHO                                                         'GET%0A'
   11     2        FETCH_OBJ_R                                          ~1      'attributes'
          3        ARRAY_KEY_EXISTS                                             !0, ~1
          4      > JMPZ                                                         ~2, ->8
   12     5    >   FETCH_OBJ_R                                          ~3      'attributes'
          6        FETCH_DIM_R                                          ~4      ~3, !0
          7      > RETURN                                                       ~4
   15     8    >   INIT_FCALL                                                   'trigger_error'
          9        ROPE_INIT                                         3  ~6      'Property+'
         10        ROPE_ADD                                          1  ~6      ~6, !0
         11        ROPE_END                                          2  ~5      ~6, '+does+not+exist'
         12        SEND_VAL                                                     ~5
         13        DO_ICALL                                                     
   16    14      > RETURN                                                       null
   17    15*     > RETURN                                                       null

End of function __get

End of class Coalescing.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
131.29 ms | 484 KiB | 9 Q