Quick tip for the VSCode PHP people out there.
Ever had an unsightly red line appear under your code telling you there’s an error that you know is a false positive?
Happily VSCode’s Intelephense extension has an undocumented feature called @disregard
that can be used to supress these “errors”. Taking the form of an annotation, the template is
./** @disregard [OPTIONAL_CODE] [OPTIONAL_DESCRIPTION] */
The annotation must go before the full block that contains the issue. So if you have an array (as pictured), it goes above the array, if you have an if
block it goes above that and so on.
Here’s our suppressed error:
While the code and description part of the annotation are optional, including them makes our code easier to understand and our error suppression more precise (we don’t want to accidentally suppress a legit error in a code block).