3v4l.org

run code in 300+ PHP versions simultaneously
<?php class NullableA { private function __construct() {} public ?string $string; public static function &string(?string $defaultValue = null) { $type = new self; $type->string = $defaultValue; return $type->string; // type is garbage collected } } class NullableB { private static $antiGarbageCollect = []; private function __construct() {} public ?string $string; public static function &string(?string $defaultValue = null) { $type = new self; self::$antiGarbageCollect[] = $type; $type->string = $defaultValue; return $type->string; } } $a =& NullableA::string(); $a = 123; var_dump($a); $b =& NullableB::string(); $b = 123; var_dump($b);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ctEgn
function name:  (null)
number of ops:  15
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   INIT_STATIC_METHOD_CALL                                  'NullableA', 'string'
          1        DO_FCALL                                      0  $2      
          2        ASSIGN_REF                                               !0, $2
   31     3        ASSIGN                                                   !0, 123
   32     4        INIT_FCALL                                               'var_dump'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
   34     7        INIT_STATIC_METHOD_CALL                                  'NullableB', 'string'
          8        DO_FCALL                                      0  $6      
          9        ASSIGN_REF                                               !1, $6
   35    10        ASSIGN                                                   !1, 123
   36    11        INIT_FCALL                                               'var_dump'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Class NullableA:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ctEgn
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E > > RETURN                                                   null

End of function __construct

Function string:
Finding entry points
Branch analysis from position: 0
Return found
filename:       /in/ctEgn
function name:  string
number of ops:  9
compiled vars:  !0 = $defaultValue, !1 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV_INIT                                        !0      null
    9     1        NEW                          self                $2      
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $2
   10     4        ASSIGN_OBJ                                               !1, 'string'
          5        OP_DATA                                                  !0
   11     6        FETCH_OBJ_W                                      $6      !1, 'string'
          7      > RETURN_BY_REF                                            $6
   13     8*     > RETURN_BY_REF                                            null

End of function string

End of class NullableA.

Class NullableB:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ctEgn
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E > > RETURN                                                   null

End of function __construct

Function string:
Finding entry points
Branch analysis from position: 0
Return found
filename:       /in/ctEgn
function name:  string
number of ops:  12
compiled vars:  !0 = $defaultValue, !1 = $type
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV_INIT                                        !0      null
   23     1        NEW                          self                $2      
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $2
   24     4        FETCH_STATIC_PROP_W          global              $5      'antiGarbageCollect'
          5        ASSIGN_DIM                                               $5
          6        OP_DATA                                                  !1
   25     7        ASSIGN_OBJ                                               !1, 'string'
          8        OP_DATA                                                  !0
   26     9        FETCH_OBJ_W                                      $8      !1, 'string'
         10      > RETURN_BY_REF                                            $8
   27    11*     > RETURN_BY_REF                                            null

End of function string

End of class NullableB.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.07 ms | 1003 KiB | 14 Q