vscode-intelephense icon indicating copy to clipboard operation
vscode-intelephense copied to clipboard

Built-in functions marked as undefined

Open IanVS opened this issue 4 years ago • 51 comments

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.

IanVS avatar Feb 03 '20 17:02 IanVS

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

bmewburn avatar Feb 03 '20 22:02 bmewburn

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

IanVS avatar Feb 04 '20 16:02 IanVS

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

ffl-russellweed avatar Feb 06 '20 16:02 ffl-russellweed

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.

christopheralert avatar Feb 06 '20 23:02 christopheralert

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 avatar Feb 10 '20 16:02 ilyaguy

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

KapitanOczywisty avatar Feb 10 '20 17:02 KapitanOczywisty

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.

joyfullservice avatar Feb 17 '20 22:02 joyfullservice

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.

ffl-russellweed avatar Mar 03 '20 20:03 ffl-russellweed

Is this still a problem in 1.4?

bmewburn avatar Jun 01 '20 07:06 bmewburn

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?

ffl-russellweed avatar Jun 01 '20 15:06 ffl-russellweed

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.

bosconian-dynamics avatar Jun 20 '20 18:06 bosconian-dynamics

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?

bosconian-dynamics avatar Jun 20 '20 18:06 bosconian-dynamics

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)

artfulrobot avatar Jul 15 '20 15:07 artfulrobot

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.

ccjjmartin avatar Aug 21 '20 19:08 ccjjmartin

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

fernandopsilveira avatar Oct 06 '20 14:10 fernandopsilveira

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

phuze avatar Oct 13 '20 07:10 phuze

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...

anrikun avatar Oct 27 '20 13:10 anrikun

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

rantsh avatar Oct 28 '20 21:10 rantsh

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.

AleeeKoi avatar Oct 30 '20 15:10 AleeeKoi

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

geri777 avatar Oct 31 '20 09:10 geri777

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

miyu4u avatar Nov 16 '20 00:11 miyu4u

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.

Polfo avatar Nov 17 '20 09:11 Polfo

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 avatar Nov 29 '20 14:11 asheroto

@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.

anrikun avatar Nov 29 '20 17:11 anrikun

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

asheroto avatar Nov 30 '20 15:11 asheroto

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!

parzibyte avatar Jan 20 '21 19:01 parzibyte

I have the same behavior with intelephense and neovim-lsp. Someone suggests to "reindex workspace" in vscode. How to do it in neovim?

adrianofoschi avatar Mar 28 '21 13:03 adrianofoschi

It'd been a while since I touched PHP and when a small gig came my way figured I'd upgrade my tooling and workflows and tried Intelephense.

Right out of the gate, built-in PHP functions are flagged as undefined. I thought I'd add a comment in case its helpful to note that I was starting from a blank slate PHP wise: the VSCode on the machine I'm using has nothing else related to PHP installed that could be conflicting with this, no prior versions or old settings, etc. Running MacOS with the Apple built-in php locally.

Restarting VS Code did not help. Changing the PHP version in the extension settings per @bosconian-dynamics suggestion above did not work for me.

Intelephense first thinks built-in functions belong to my namespace ("Undefined function 'ProjectNamesSpace\Plugin\defined'") and if I prefix them with a \ it still reports the same issue but without re my namespace ("Undefined function 'file_exists'").

firxworx avatar Apr 11 '21 02:04 firxworx

@firxworx have you tried "Index workspace" in the command palette as well?

Admittedly I didn't try it when I initially experienced the issue, but others have reported success with it. I haven't been able to replicate the issue once more to test it myself, sadly.

bosconian-dynamics avatar Apr 11 '21 18:04 bosconian-dynamics

+1 Remote server via ssh setup Intelephense 1.7.1 php version set to 5.6 Intelephense reindex didn't change anything. All core php functions are undefined yet show the definition as in screenshot. PHP Classes undefined with no definition. Custom classes built into the software I'm working on are fine. image

Installing 1.7.0 and restarting VS Code fixes the problem.

[UPDATE] Apparently only solved problem for the window i downgraded the version on. Another window, same SSH remote connection, still has the problem even after restart. The issue triggers a couple minutes after restarting vscode (large project). I can't seem to get my other window to work right, even after reindex/restarts.

fmp777 avatar May 16 '21 17:05 fmp777

Anyone here suggest a better extension then? even though I paid for the pro version, doesn't seem like the author wants to respond or fix critical bugs like this.

fmp777 avatar May 17 '21 16:05 fmp777

I'd like to solve the issue but I need to be able to reproduce it first. @fmp777 can you provide any output tab logs? Or a reproducible example/steps? Did you try uninstalling and reinstalling the extension?

bmewburn avatar May 17 '21 20:05 bmewburn

I'm new to vscode, so i'm not sure what you mean by output tab logs. Downgrading to previous version helped most my windows, because most of them are smaller code bases. The largest codebase window is still producing this error. As mentioned previously these are remote ssh - and I had to vastly increase my server side file watcher limit to get vscode to work. The sheer size may be the problem for intelephense?

uninstall / install intelephense did not change the outcome

fmp777 avatar May 20 '21 17:05 fmp777

Hello, I'm having similar issues, which led me here. I'm on the most recent version of VS Code and the most recent version of intelephense.

Installed, restarted. Uninstalled, restarted, reinstalled, restarted - still didn't help. I've "re-indexed workspace" several times.

Also, I don't know if it's related, but as a test project I created a simple php script with default php functions as well as some defined functions. The PHP functions still came up as undefined. As well, the custom functions I defined cannot be found either leading to autocompletion not working.

Does it matter that I'm on the Apple M1 chip?

I'm also new to VSCode, coming from PHPStorm.

If you have a formal set of steps I can try to debug and report back, please let me know.

blue928 avatar May 28 '21 22:05 blue928

It worked flawlessly until about 2 or 3 months ago.

asheroto avatar May 28 '21 23:05 asheroto

I’m on Apple M1 too. Not sure it should matter, but never know.

fmp777 avatar May 29 '21 02:05 fmp777

Using a custom built computer with Intel i7-4790k 4GHz.

asheroto avatar May 29 '21 02:05 asheroto

There was an issue with apple M1 previously #1550 . You can also provide your own nodejs runtime with the intelephense.runtime setting which is worth trying for M1 users.

It's hard to see a pattern here. There seems to be a various OS and vscode/intelphense versions. Please post if there is any obvious errors in the output tab: View -> Output -> intelephense.

bmewburn avatar May 29 '21 09:05 bmewburn

we're still having issued with this. in-built functions are showing up as undefined on my Mac OS + VS Code.

AyoCodess avatar Aug 25 '21 10:08 AyoCodess

Had same problem in v1.7.1 while using Laravel PHP. It was showing error on built-in functions. But just found the solution: go to extension setting @ext:bmewburn.vscode-intelephense-client and disable one by one Intelephense › Diagnostics: and you will see the error showing will stop.

UzairKhalil avatar Sep 23 '21 18:09 UzairKhalil

I had the same issue when I manually added the intelephense.stubs manually to my settings.json with only one item in the array (wordpress). It seems that the standard settings are then overwritten, thus all standard libraries are missing. Using the settings as described on stackoverflow helped me to preserve the standard libraries while adding the wordpress functions: https://stackoverflow.com/a/65275602

toovy avatar Nov 03 '21 10:11 toovy

Having this problem, I downgraded. Its only in one of my projects. Also interestingly, it only higlihgited some functions. Like date_default_timezone_set and json_decode. Those also didnt load up in my autocomplete. Also noteable that running top on the server I had ssh'd into was peggeing node at like 35+ CPU constantly. I would reindex, the errors would disappear, then on typing or saving something, the errors would reappear.

Here's the debug console from when it is not working https://pastebin.com/UaY6h4QU

And one from after i downgraded: https://pastebin.com/1eXuQCMg

Oh its breaking again on the older version. just for json_encode and header, empty works ok hash doesnt work. base64_encode ...

dskzz avatar Dec 15 '21 23:12 dskzz

Oh snap I thought this issue was from Feb 2022 and I thought "wow that's a long time to let a counterproductive bug go".

Then I realized this was 2020! Probably safe to assume it's not getting addressed... Screen Shot 2022-04-18 at 8 14 50 AM Apparently both isdir and preg_replace do not exist 🤷

working-name avatar Apr 18 '22 12:04 working-name

Hi all,

After updating to a newer M1 Mac I had the same issue as described above and @toovy 's answer completely fixed the issue for me. I had defined stubs for Core and WordPress in my VSCode settings.json as follows:

"intelephense.stubs": [
    "Core",
    "wordpress"
],

It was only when I deleted all of the above that my definitions began to work again for core PHP functions like range() and array_flip().

It's hard to say if this issue is specifically related to M1 Macs/MacOS or the WordPress snubs but by completely removing the stubs definitions in settings.json everything works - I get Intelephense tooltips for both WordPress features and also for core PHP functions.

roryashfordbentley avatar Jun 08 '22 13:06 roryashfordbentley

image

by completely removing the stubs definitions in settings.json everything works

I don't have them set at all:

$ uname -a
Linux hpdesktop 5.15.0-39-generic #42-Ubuntu SMP Thu Jun 9 23:42:32 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ code --version
1.68.1
30d9c6cd9483b2cc586687151bcbcd635f373630
x64
$ grep intelephense ~/.config/Code/User/settings.json 
    "intelephense.environment.phpVersion": "8.1.2",
$ php -v
PHP 8.1.2 (cli) (built: Jun 13 2022 13:52:54) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

Intelephense version:

v1.8.2
---
Released on
16/04/2017, 15:34:28
Last updated
22/02/2022, 21:53:55
Identifier
bmewburn.vscode-intelephense-client

What's weird is that this system is (VSCode-)synced to another computer that doesn't demonstrate this problem...

image

(Note that is has picked up on a problem with $argv, so it is checking stuff.)

$ uname -a
Linux hpnotebook 5.13.0-41-generic #46-Ubuntu SMP Thu Apr 14 20:06:04 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

$ code --version
1.68.1
30d9c6cd9483b2cc586687151bcbcd635f373630
x64

$ grep intelephense ~/.config/Code/User/settings.json
    "intelephense.environment.phpVersion": "8.1.2",

$ php -v
PHP 8.0.8 (cli) (built: Jun 13 2022 13:51:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies

pauljherring avatar Jun 27 '22 14:06 pauljherring