3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); final class SomeStringable { public function __toString(): string { echo "__toString executed" . PHP_EOL; return "foo"; } } final class SomeClass { public function __construct(public ?string $value) {} } $nullableVar = new SomeStringable(1); //$nullableVar = null; //$result = new SomeClass(null === $nullableVar ? null : (string) $nullableVar); // works $result = new SomeClass($nullableVar); // Fatal error var_dump($result->value);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBatI
function name:  (null)
number of ops:  14
compiled vars:  !0 = $nullableVar, !1 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   DECLARE_CLASS                                                'somestringable'
   17     1        NEW                                                  $2      'SomeStringable'
          2        SEND_VAL_EX                                                  1
          3        DO_FCALL                                          0          
          4        ASSIGN                                                       !0, $2
   20     5        NEW                                                  $5      'SomeClass'
          6        SEND_VAR_EX                                                  !0
          7        DO_FCALL                                          0          
          8        ASSIGN                                                       !1, $5
   22     9        INIT_FCALL                                                   'var_dump'
         10        FETCH_OBJ_R                                          ~8      !1, 'value'
         11        SEND_VAL                                                     ~8
         12        DO_ICALL                                                     
         13      > RETURN                                                       1

Class SomeStringable:
Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OBatI
function name:  __toString
number of ops:  4
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   ECHO                                                         '__toString+executed%0A'
    8     1      > RETURN                                                       'foo'
    9     2*       VERIFY_RETURN_TYPE                                           
          3*     > RETURN                                                       null

End of function __tostring

End of class SomeStringable.

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

End of function __construct

End of class SomeClass.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
124.18 ms | 480 KiB | 8 Q