3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Coalescing { protected $attributes = [ 'attribute1' => 'value1', ]; public function __isset($name) { return array_key_exists($name, $this->attributes); } 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
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hg4Wf
function name:  (null)
number of ops:  16
compiled vars:  !0 = $coal
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   NEW                                              $1      'Coalescing'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   28     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                                                 
   32     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                                                 
   34    15      > RETURN                                                   1

Class Coalescing:
Function __isset:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hg4Wf
function name:  __isset
number of ops:  5
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
   10     1        FETCH_OBJ_R                                      ~1      'attributes'
          2        ARRAY_KEY_EXISTS                                 ~2      !0, ~1
          3      > RETURN                                                   ~2
   11     4*     > RETURN                                                   null

End of function __isset

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/hg4Wf
function name:  __get
number of ops:  16
compiled vars:  !0 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   15     1        ECHO                                                     'GET%0A'
   16     2        FETCH_OBJ_R                                      ~1      'attributes'
          3        ARRAY_KEY_EXISTS                                         !0, ~1
          4      > JMPZ                                                     ~2, ->8
   17     5    >   FETCH_OBJ_R                                      ~3      'attributes'
          6        FETCH_DIM_R                                      ~4      ~3, !0
          7      > RETURN                                                   ~4
   20     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                                                 
   21    14      > RETURN                                                   null
   22    15*     > RETURN                                                   null

End of function __get

End of class Coalescing.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.31 ms | 1400 KiB | 17 Q