Undefined type 'Imagick' in VSCode's intelephense
Asked Answered
G

1

36

I had an issue where I installed Imagick via Pecl and Intelephense didn't know what to do with that extension and failed to show any code completion even though the extension was properly installed in the php.ini file and was working fine.
Some screenshots to bring clarity:

  1. Code where Imagick is used
  2. Bash output showing that the imagick extension is installed in the php.ini:
ddruganov@MBP-Demid:~$ php -i | grep imagick
imagick
imagick module => enabled
imagick module version => 3.4.4
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0
imagick.skip_version_check => 0 => 0
  1. Bash output showing where the extension is located:
ddruganov@MBP-Demid:~$ mdfind imagick.so
/usr/local/lib/php/pecl/20190902/imagick.so
Gopak answered 8/6, 2020 at 9:6 Comment(1)
If you copy-paste code/shell text it will be easier to read while mantaining the post context and searchable.Jackpot
G
96

Turns out intelephense just wasn't configured to know what this extension is.
The solution is very simple:

  1. Go to Intelephense extension settings in VSCode
  2. Go to a setting called 'Intelephense: Stubs'
  3. Add a new item named 'imagick'
  4. Save and close settings (though I believe they are saved
    automatically)
  5. Done

After all this is done, Intelephense shows all info about Imagick and auto-complete works just fine: proof

Hope this helps someone!

Gopak answered 8/6, 2020 at 9:13 Comment(1)
Thanks, worked like a charm. Just adding MongoDB in php.stubs (I am using @ext:DEVSENSE.phptools-vscode) removed all the warnings related to MongoDB extensions classes + start getting type hints for all the stuff, MongoDB extension includes.Xanthene

© 2022 - 2024 — McMap. All rights reserved.