Tested on PHP7.3, psalm version: up to the newest (3.5.3)
Consider this: https://psalm.dev/r/c95cb42db4
<?php declare(strict_types=1);
error_reporting(E_ALL);
$v = 42;
['a' => $a, 'b' => $b] = $v;
$c = $v['a'];
$d = $v['b'];
// $a = NULL, $b = NULL, $c = NULL, $d = NULL
var_dump($a, $b, $c, $d);
Expected behavior:
psalm detects that no variables $a and $b can be pulled out of a non-array variable.
Actual behavior:
psalm does not detect any issues with that code. $a and $b are null, which causes a bug to go unnoticed.
I find it problematic that php does not find anything wrong with that, even with strict_types and error_reporting all enabled: http://sandbox.onlinephpfunctions.com/code/f99be1f5ba18ccb98dceddee8dda092076e4f744
But imo psalm should detect this.
Thanks
Sorry, please try again - there was an issue with the online Psalm playground, now fixed.
But indeed, it still does not complain about ['a' => $a, 'b' => $b] = 42;
Wait it does now complain about it.
Does this mean the live test was running an older version and the newer one detects it?
//e: jumped the gun, it complains about one but not both example. got it
No, the online playground was just broken for about 12 hours
Most helpful comment
But indeed, it still does not complain about
['a' => $a, 'b' => $b] = 42;