Vscode-intelephense: Built-in functions marked as undefined

Created on 3 Feb 2020  路  26Comments  路  Source: bmewburn/vscode-intelephense

Describe the bug
Just recently, intelephense has started marking lots of function calls as undefined, for instance is_null and array_map.

To Reproduce
Install version 1.3.6 or later. Seems to work fine in 1.3.5.

Expected behavior
Built-in functions are not flagged as undefined.

Screenshots
image

Platform and version
OS and Intelephense version.
MacOS 10.15. Versions mentioned above.

needs more info

Most helpful comment

I am running the v1.5.4 of PHP Intelephense on the latest version of VSCode for Debian based installs and running into this issue. Specifically I am within a file that uses a namespace and anything (function, class, etc) in the global space is showing as undefined, when I define it as within the global space by adding a \ in front of it, it still shows as undefined.

The error might be related to hitting save too quickly. If I reindex the workspace the error goes away but if I hit save (within say 4-5 seconds) and trigger a check of the file the error comes back, however if I wait a while before hitting save the error seems to stay away. I am using a huge code base with millions of lines of code so maybe it isn't finishing indexing and this is what causes the error?

I found it in another thread but ctrl + shift + p > index workspace is how I am reindexing.

I have tried uninstalling and installing this extension from scratch but that did not fix it.

All 26 comments

Have you modified any of the default settings? These definitions are bundled with the extension and controlled with the intelephense.stubs setting.

I hadn't, no. After I got the errors, I tried setting my php version to 7.3, with no observable effect.

I'm having the same issue. Reverting to 1.3.5 fixed it for now.

Only extension setting I have changed from default is "intelephense.format.enable": false

I noticed the same issue. sqlsrv commands also started popping up red around this time. Reverting to 1.3.5 also fixed it for me.

I noticed "sqlsrv" was no longer included in the stubs settings. However, adding it back did not resolve the issue, whereas rolling back the version did.

Intelephense doesn't know about deprecated functions.
I have old project which run on php5.6 and intelephence show error "intelephense: Undefined function 'mysql_fetch_assoc'."

@ilyaguy Set "intelephense.environment.phpVersion": "5.6.0" and add "mysql" to "intelephense.stubs"

Same problem here, even with built-in php functions like preg_replace and json_encode. Reverting to version 1.3.5 got me back up and running again.

I got the later versions working. I failed to notice a crucial step in the Quick Start:

Disable the built-in VSCode PHP Language Features.

Whoops. Doing so and restarting made everything work correctly.

Is this still a problem in 1.4?

This was still happening as of version 1.4.1/1.4.0.

I decided to check my @builtin php extensions and accidentally turned off "PHP Language Basics", which did syntax highlighting. After turning it back on and restarting, now everything is working?

Happening for me on the following configuration:

  • Windows 10 Pro x64 18362.900
  • Intelephense v1.4.1
  • Default Intelephense configuration
  • PHP 7.4.0
  • PHP Language Features disabled
  • PHP Language Basics enabled
  • Additional PHP extensions: PHP Debug, PHP DocBlocker, PHP Sniffer

Toggling either of the built-in language packages has no effect. Toggling the other PHP extensions has no effect.

I just set "intelephense.environment.phpVersion" to something else - "7.0.0" in this case - and the standard-lib functions stopped highlighting as undefined. In removing the setting thereafter (defaulting to "7.4.0" once again) the effect persisted.

Seems like changing the the PHP version setting rebuilt the relevant cache with whatever was initially missing?

I get the same (using intellephense 1.3.11) but on mine it says built-in functions are deprecated:

image

(edit: I reinstalled and now it seems happy)

I am running the v1.5.4 of PHP Intelephense on the latest version of VSCode for Debian based installs and running into this issue. Specifically I am within a file that uses a namespace and anything (function, class, etc) in the global space is showing as undefined, when I define it as within the global space by adding a \ in front of it, it still shows as undefined.

The error might be related to hitting save too quickly. If I reindex the workspace the error goes away but if I hit save (within say 4-5 seconds) and trigger a check of the file the error comes back, however if I wait a while before hitting save the error seems to stay away. I am using a huge code base with millions of lines of code so maybe it isn't finishing indexing and this is what causes the error?

I found it in another thread but ctrl + shift + p > index workspace is how I am reindexing.

I have tried uninstalling and installing this extension from scratch but that did not fix it.

I am running the v1.5.4 of PHP Intelephense on the latest version of VSCode for Debian based installs and running into this issue. Specifically I am within a file that uses a namespace and anything (function, class, etc) in the global space is showing as undefined, when I define it as within the global space by adding a \ in front of it, it still shows as undefined.

The error might be related to hitting save too quickly. If I reindex the workspace the error goes away but if I hit save (within say 4-5 seconds) and trigger a check of the file the error comes back, however if I wait a while before hitting save the error seems to stay away. I am using a huge code base with millions of lines of code so maybe it isn't finishing indexing and this is what causes the error?

I found it in another thread but ctrl + shift + p > index workspace is how I am reindexing.

I have tried uninstalling and installing this extension from scratch but that did not fix it.

I've got the exact same behavior here
Intelephense v1.5.4
VSCode v1.49.3
Windows NT x64 10.0.18363

I'm seeing the same behaviour as well -- some built-in functions are throwing an Undefined function warning. strtoupper and str_replace are a couple examples.

Undefined function 'MyProject\MyApp\Helpers\str_replace'. intelephense(1010)

I've tried re-installing the extension and changing the PHP environment version; neither having an effect. I also have no other extensions installed which provide similar functionality, that may cause some sort of conflict.

Intelephense: 1.5.4
VSCode: 1.50.0
PHP Language Basics: enabled
PHP Language Features: disabled

Same problem here.
What is strange is that I only have this problem with a project but not another one. Both have the same settings though...

EDIT: uninstalling, installing an older version then upgrading to latest magically fixed the problem...

I'm not sure if this is of any help, but I was having this problem right now, reindexed the workspace and the errors went away.

For the sake of clarity (and perhaps future reference to myself) this is exactly what I did: I opened a file that was showing the wrong errors, then clicked on the option below and it all seems good now

image

Hello,
I got this undefined error using array_keys core function.
Downgrading from 1.5.4 > 1.5.3 make my IDE works again without showing wrong errors.

Yes, downgrading to 1.5.3 fixes the issue. I had the same problem - some projects worked well others not. I was using Version 1.5.4

image

After downgrading to 1.5.3 everything worked well

Thx @geri777 @AleeeKoi .
I had same issue about built_in php function, but it fixed by downgrade to v1.5.3.

I'm not sure if this is of any help, but I was having this problem right now, reindexed the workspace and the errors went away.

For the sake of clarity (and perhaps future reference to myself) this is exactly what I did: I opened a file that was showing the wrong errors, then clicked on the option below and it all seems good now

image

Intelephense: Index workspace solved the undefined function issue for me too. Changing PHP version did not.

Hello,

I'm having the same issue as well. Downgrading to 1.5.3 and reloading is a workaround. I don't have the "Index workspace" option.

@asheroto
Yes you have it. I thought the same at first.
You have to make sure you open Command palette (Ctrl+Shift+P) while the active tab is a PHP file.
Otherwise, when you type "Intelephense", the option won't show up.

Got it. I had to cancel indexing, restart the program, then start indexing, thanks!

I'm not sure if this is of any help, but I was having this problem right now, reindexed the workspace and the errors went away.

For the sake of clarity (and perhaps future reference to myself) this is exactly what I did: I opened a file that was showing the wrong errors, then clicked on the option below and it all seems good now

image

Yes, it fixed the problem in my case. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aleksandervines picture aleksandervines  路  3Comments

9brada6 picture 9brada6  路  3Comments

superadmini picture superadmini  路  4Comments

vanasis picture vanasis  路  4Comments

ghost picture ghost  路  3Comments