3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** @template T of string|null */ class StringOrNull { /** @var T */ public ?string $value; /** @param T $value */ public function __construct(?string $value) { $this->value = $value; } /** * @template T2 of string|int * @param T2 $value * @psalm-this-out self<T2> */ public function setFromStringOrInt(string|int $value): void { if (is_string($value)) { // This is a separate issue, probably https://github.com/vimeo/psalm/issues/7739 $this->value = $value; } } } class Foo { /** @var list<StringOrNull<null>> */ private array $nulls = []; /** @param list<StringOrNull<null>> $nulls */ public function __construct(array $nulls) { $this->nulls = $nulls; } public function assertAllNull(): void { foreach ($this->nulls as $null) { assert($null->value === null); } } } $stringOrNull = new StringOrNull(null); $foo = new Foo([$stringOrNull]); $stringOrNull->setFromStringOrInt("foobar"); $foo->assertAllNull();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mKN4o
function name:  (null)
number of ops:  15
compiled vars:  !0 = $stringOrNull, !1 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   NEW                                              $2      'StringOrNull'
          1        SEND_VAL_EX                                              null
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
   47     4        NEW                                              $5      'Foo'
          5        INIT_ARRAY                                       ~6      !0
          6        SEND_VAL_EX                                              ~6
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !1, $5
   48     9        INIT_METHOD_CALL                                         !0, 'setFromStringOrInt'
         10        SEND_VAL_EX                                              'foobar'
         11        DO_FCALL                                      0          
   49    12        INIT_METHOD_CALL                                         !1, 'assertAllNull'
         13        DO_FCALL                                      0          
         14      > RETURN                                                   1

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

End of function __construct

Function setfromstringorint:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
filename:       /in/mKN4o
function name:  setFromStringOrInt
number of ops:  6
compiled vars:  !0 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
   20     1        TYPE_CHECK                                   64          !0
          2      > JMPZ                                                     ~1, ->5
   22     3    >   ASSIGN_OBJ                                               'value'
          4        OP_DATA                                                  !0
   24     5    > > RETURN                                                   null

End of function setfromstringorint

End of class StringOrNull.

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

End of function __construct

Function assertallnull:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 11
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/mKN4o
function name:  assertAllNull
number of ops:  13
compiled vars:  !0 = $null
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   40     0  E >   FETCH_OBJ_R                                      ~1      'nulls'
          1      > FE_RESET_R                                       $2      ~1, ->11
          2    > > FE_FETCH_R                                               $2, !0, ->11
   41     3    >   ASSERT_CHECK                                             
          4        INIT_FCALL                                               'assert'
          5        FETCH_OBJ_R                                      ~3      !0, 'value'
          6        TYPE_CHECK                                    2  ~4      ~3
          7        SEND_VAL                                                 ~4
          8        SEND_VAL                                                 'assert%28%24null-%3Evalue+%3D%3D%3D+null%29'
          9        DO_ICALL                                                 
   40    10      > JMP                                                      ->2
         11    >   FE_FREE                                                  $2
   43    12      > RETURN                                                   null

End of function assertallnull

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.55 ms | 989 KiB | 14 Q