Home > Mobile >  Some PHP Function Flagged as Error in VSCode
Some PHP Function Flagged as Error in VSCode

Time:01-13

I am a beginner and am developing a specific web system using PHP 8.2, Codeigniter 4 and XAMPP in VSCode. However, in my Controller, some PHP functions are marked as errors, such as password_verify(), strpos() etc. After I run it, the program runs fine. Where is the error? Is it in the VS Code program?

the vs code screenshot

The problem is:

Expected type 'string'. Found 'array|null'.intelephense(1006)

For additional information, I am using Intelephense PHP extension 1.9.2. I also opened the code in PHPStorm and the error is not there. Thank you for any provided information.

When I uninstalled / disabled the Intelephense PHP, of course the error was not found. Whe I use PHP IntelliSense, it's did not even mark the function as an error. However, when Intelephense was re-enabled the PHP function was still marked as an error.

CodePudding user response:

I see that $request->getPost() has a signature of mixed|null. And password_verify a a signature of string.

You can cast it to string and the warning will dissapear.

$password = (string) $this->request->getPost('password')
  • Related