Vscode-intelephense: Calls to defined() should disable undefined constant checks for that symbol

Created on 11 Jan 2020  路  8Comments  路  Source: bmewburn/vscode-intelephense

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'));
diagnostics

Most helpful comment

This error flag is clearly wrong:

All 8 comments

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dgunay picture dgunay  路  3Comments

ghost picture ghost  路  3Comments

superadmini picture superadmini  路  4Comments

pseudoanime picture pseudoanime  路  3Comments

Ilyes512 picture Ilyes512  路  3Comments