3v4l.org

run code in 300+ PHP versions simultaneously
<?php function assignIfSet($testable, &$assigned) { if(isset($testable)) { $assigned = $testable; return true; } $assigned = null; return false; } $arr = [ 'foo' => (object)[ 'bar' => (object)[ 'zigi' => 1 ] ] ]; $foo = 'bogus'; if(assignIfSet($arr['foo']->bar->zigi, $foo)) { echo $foo; } else { echo 'Failure'; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FpQeC
function name:  (null)
number of ops:  18
compiled vars:  !0 = $arr, !1 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   CAST                                          8  ~2      <array>
          1        INIT_ARRAY                                       ~3      ~2, 'bar'
          2        CAST                                          8  ~4      ~3
          3        INIT_ARRAY                                       ~5      ~4, 'foo'
   13     4        ASSIGN                                                   !0, ~5
   21     5        ASSIGN                                                   !1, 'bogus'
   23     6        INIT_FCALL                                               'assignifset'
          7        FETCH_DIM_R                                      ~8      !0, 'foo'
          8        FETCH_OBJ_R                                      ~9      ~8, 'bar'
          9        FETCH_OBJ_R                                      ~10     ~9, 'zigi'
         10        SEND_VAL                                                 ~10
         11        SEND_REF                                                 !1
         12        DO_FCALL                                      0  $11     
         13      > JMPZ                                                     $11, ->16
   24    14    >   ECHO                                                     !1
         15      > JMP                                                      ->17
   26    16    >   ECHO                                                     'Failure'
   27    17    > > RETURN                                                   1

Function assignifset:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/FpQeC
function name:  assignIfSet
number of ops:  9
compiled vars:  !0 = $testable, !1 = $assigned
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ISSET_ISEMPTY_CV                                         !0
          3      > JMPZ                                                     ~2, ->6
    5     4    >   ASSIGN                                                   !1, !0
    6     5      > RETURN                                                   <true>
    9     6    >   ASSIGN                                                   !1, null
   10     7      > RETURN                                                   <false>
   11     8*     > RETURN                                                   null

End of function assignifset

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.72 ms | 1399 KiB | 14 Q