vscode-intelephense
vscode-intelephense copied to clipboard
Calls to defined(), function_exists, method_exists should disable undefined symbol checks
https://www.php.net/manual/en/function.defined.php
The same could be said for class_exists
, function_exists
, method_exists
etc.
https://www.php.net/manual/en/function.class-exists.php
This would be a way of controlling false diagnostics using PHP code rather than relying on non-standard @suppress
or @noinspect
phpdoc annotations.
assert(class_exists('Foo'));
class_exists
will suppress also method calls to this class? Idea is interesting, but will result for sure with angry bug reports :) I mean, following example is ridicules and probably @suppress
/@noinspect
would be way better.
function a():void{
assert(class_exists('Foo'));
$f = new Foo;
assert(method_exists('Foo', 'test'));
$f->test();
}
Just as example psalm assumes mixed
in such cases https://psalm.dev/r/a5a6a62123 (and can't deal with this example)
class_exists
, rand
Send error "undefined function" because this occurs?
@LeninZapata no, if you are seeing errors on these then it is unrelated. Please open a new ticket and include the settings you are using.
This error flag is clearly wrong:
any news on this?
Same problem when working with WooCommerce and using the contant WOOCOMMERCE_VERSION.
any progress??
@bmewburn any updates?
This setting will do the job (dirty way):
"intelephense.diagnostics.undefinedConstants": false
This error flag is clearly wrong:
You can use the constant function
constant("DISABLE_NAG_NOTICES")
any progress? (for following)
@fabienwnklr I suggest that you use the PHP built in function "constant" to check for existence of constants.
@CyrusJoudieh Yeah i read this, but i use many constant in my project, i think it's very time-consuming..
@fabienwnklr I suggest that you use the PHP built in function "constant" to check for existence of constants.
That doesn't resolve the case for function_exists()
and the others.
Send error "undefined function" because this occurs?
facing same issue on recent updates

Intelephese version v1.9.1
Any updates on this?
Came here also wondering if there is any good solution for this.
Send error "undefined function" because this occurs?
facing same issue on recent updates
![]()
Intelephese version
v1.9.1
@feryardiant I think this is a separate issue where the random stubs aren't in the default set anymore. If you add "random" to the intelephense.stubs
setting that should fix your issue.
What is suggested here?
if (defined('WP_ENV')) {
if (WP_ENV === 'development') {
// Undefined constant 'WP_ENV'.intelephense(1011)
} else {
// The constant is not defined
}
} else {
}
Same error when using constant('WP_ENV')
as the condition.
Same error when using
constant('WP_ENV')
as the condition.
The "workaround" is to use the constant('WP_ENV')
call instead of the direct constant WP_ENV
in the equality statement. But then, there is no validation by intelephense whether the constant really exists or not. Might as well use "intelephense.diagnostics.undefinedConstants": false
in the settings, which does the same thing overall.
There's no real solution until this bug is dealt with.
Please solve this bug, it's still opened after 3 years!