Search code examples
phpvisual-studio-codeintelephense

PHP : VS code + >Intelephense detect an error on references passed in foreach (and in functions)


VS Code detect errors on my php code when I try to use a reference in a foreach. This should be possible refering to PHP doc : https://www.php.net/manual/en/control-structures.foreach.php

$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
    $value = $value * 2;
}

My code is exactly the same :

$ret = [1,2,3,4] ;
foreach ( $ret as &$v )
     $v = $v * 2 ;

but VS Code still show me errors on it, and I don't know how to remove these warnings (code is working)

Any idea why ? Thanks a lot for your help !

enter image description here

enter image description here

enter image description here

enter image description here

PS : i know this code is stupid, it's just an example.


Solution

  • That was not a problem Intelephense, but with PHP IntelliSense : https://github.com/felixfbecker/vscode-php-intellisense

    Disabling it remove the errors i had. I did not post an issue on intellisense Github.