0

Has anyone configured VS Code to show syntax/semantic errors in PHP development? Coming from full Visual Studio/C# world, I really miss this thing a lot. Currently I actually have to call my PHP function using a client, only to get a HTTP 500 error and then check server logs to see what went wrong. This is a huge pain. Going through all of this only to find for example that I didn't import a require namespace, is so frustrating.

I understand that PHP by design cannot detect all kinds of errors like C# at compile time (so to speak), but detecting functions that do not exist or not passing required parameters should be easy to catch.

Is there a plug-in or setting in VS Code that could handle syntax/semantic error in PHP code? I'm using Laravel on the server-side, if that matters.

3
  • I have PHP IntelliSense and PHP Debug extensions. The first one will show syntax errors, and, with XDebug, you can debug your application like in C#. Commented Dec 17, 2019 at 19:23
  • @FelippeDuarte: I too have both of them installed. But it doesn't tell me if my code is missing a namespace import, which is more of a semantic error than syntax. It also doesn't tell me if I have missed a parameter. It even misses Object.Method does not exist thing. All these are caught only in the logs. XDebug on the other hand is a debug-time helper. Of course it is a great tool and helps me a lot, but it is not meant to catch semantic problems. Commented Dec 17, 2019 at 19:28
  • You can try to use psalm (psalm.dev) and its extension to VSCode. I don't use it but you can give a try. Commented Dec 17, 2019 at 20:02

1 Answer 1

3

Looks like I found something. I uninstalled PHP Intellisense extension this morning and installed PHP Intelephense and all seems to be far better. Not only that the syntax and semantic errors are highlighted, it automatically injects required namespaces too. And if that were not enough, Go To Definition (F12) command has started working correctly all of a suden. :)

Must-have extension for any PHP work in VSCode I'd say.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.