bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.64k stars 94 forks source link

Built-in functions marked as undefined #990

Closed IanVS closed 7 months ago

IanVS commented 4 years ago

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.

bmewburn commented 4 years ago

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

IanVS commented 4 years ago

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

ffl-russellweed commented 4 years ago

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

christopheralert commented 4 years ago

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.

ilyaguy commented 4 years ago

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

KapitanOczywisty commented 4 years ago

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

joyfullservice commented 4 years ago

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.

ffl-russellweed commented 4 years ago

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.

bmewburn commented 4 years ago

Is this still a problem in 1.4?

ffl-russellweed commented 4 years ago

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?

bosconian-dynamics commented 4 years ago

Happening for me on the following configuration:

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

bosconian-dynamics commented 4 years ago

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?

artfulrobot commented 4 years ago

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)

ccjjmartin commented 4 years ago

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.

fernandopsilveira commented 4 years ago

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

phuze commented 4 years ago

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

anrikun commented 4 years ago

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

rantsh commented 4 years ago

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

AleeeKoi commented 4 years ago

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.

geri777 commented 4 years ago

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

miyu4u commented 4 years ago

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

Polfo commented 4 years ago

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.

asheroto commented 3 years ago

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.

anrikun commented 3 years ago

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

asheroto commented 3 years ago

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

parzibyte commented 3 years ago

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!

adrianofoschi commented 3 years ago

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

firxworx commented 3 years ago

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'").

bosconian-dynamics commented 3 years ago

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

fmp777 commented 3 years ago

+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 commented 3 years ago

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.

bmewburn commented 3 years ago

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?

fmp777 commented 3 years ago

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

blue928 commented 3 years ago

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.

asheroto commented 3 years ago

It worked flawlessly until about 2 or 3 months ago.

fmp777 commented 3 years ago

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

asheroto commented 3 years ago

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

bmewburn commented 3 years ago

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.

AyoCodess commented 3 years ago

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

UzairKhalil commented 3 years ago

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.

toovy commented 3 years ago

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

dskzz commented 2 years ago

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

working-name commented 2 years ago

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 🤷

roryashfordbentley commented 2 years ago

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.

pauljherring commented 2 years ago

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
bkline commented 1 year ago

You can also provide your own nodejs runtime with the intelephense.runtime setting which is worth trying for M1 users.

I can confirm that I had to install my own nodejs (replacing the presumably broken one which is supplied) and register it in order to get the plugin to stop flooding the notification panel with bogus complaints that it couldn't find anything. If this is going to hit anyone with a vanilla M1 Mac I'm surprised the setup instructions make no mention of the need to do this.

[Edit] That didn't last long. After a couple of hours the bogus errors (caused by the plugin's failure to find any of the classes the site is using) are back.

bkline commented 1 year ago

A number of comments have indicated that downgrading the plugin solved the problem. How does one downgrade?

pauljherring commented 1 year ago

How does one downgrade?

Ctrl-Shift-X to get the Extensions pane up, search for the extension you want, click the Down Arrow next to Uninstall and select Install another version... and look for the version you're after.

bkline commented 1 year ago

Thanks, Paul. Unfortunately the downgrade didn't solve the problem (nor did "reindexing"). Guess it's time to research a better plugin.

pbogut commented 1 year ago

@bkline yeah, good luck with that. If you find LSP for PHP that is half decent let me know I will happily throw some cash their way. The truth is this is the best LSP for PHP. It's a bit sad that it's not OSS but still, @bmewburn does amazing work here.