Compile-time PHP errors in VSCode - php

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.

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.

Related

PhpStorm does not recognize PHP

I saw many different questions here, but nothing was helpful to me.
I have no trouble with an interpreter, I tried to reset PhpStorm's cache.
It looks like file functions.php isn't accessible.
I really don't want to make a total reset. Maybe somebody has an idea how to solve it?
I'm not sure what I actually did and how to reproduce this issue again, but now it works well. I took previous version of PHPstorm. When I installed new one, the previous one was simply renamed to sth like 'phpstorm2'.
Here are my thoughts what actually happened:
As I understand for highlighting is responsible that part of application which is managed under Languages & Frameworks / PHP / PHP Runtime.
To reproduce this issue you may try to disable there "Core / Core" and try to write down in any place of your phpfile following:
\Exception::class();
And in your case this class will not be highlighted, as it presents in Core_c.php. In my case it is placed in
/opt/phpstorm/plugins/php/lib/php.jar!/stubs/Core/Core_c.php
I'm 100% sure that these libs were always enabled, but why I didn't saw this - that is the question.
So if I face this issue again my steps would be:
Try to verify Languages & Frameworks / PHP / PHP Runtime. The better way would be to enable ALL libs.
Check External Libraries in the project tree. Check read privileges for /opt/phpstorm/plugins/php/lib/php.jar and probably reinstall this plugin.
Try to find out function which I don't actually see in External Libraries.

How to debug Yii PHP code in NetBeans

I have set-up my WAMP installation to debug a PHP website in NetBeans.
This works fine (up to a point, hence this question) and I can single-step through the PHP code, and watch variables, etc.
However, some bits of the code - those provided within the Yii framework - are throwing exceptions, but attempts to single-step through this code fail - the debugger leaps over portions of the code and I can't observe what's going on.
The debugger lands on a call to HandleError, but I can't see how it got there. The displayed Call Stack isn't showing all the steps taken to get where it is.
I've seen lots of comments on the web about this, but haven't yet seen an answer on how to enable this framework's code to be debugged on my PC.
Any suggestions would be welcome.

Dreamweaver CS5 with php 5.3 namespace tag

Dreamweaver has been my favourite IDE for programming PHP for a while.
However we have recently updated our servers to work with php 5.3.x
Now everytime I use php 5.3 specific tags like namespace dreamweaver suggests that there is a syntax error.
I would like to be able to add the namespace as a valid tag or install a plugin which does that for me. If that can't be done it would be best if I could just disable the checking for errors.
Can anyone help me out?
Thanks in advance!
Dreamweaver CS5 PHP support is limited to PHP 5.2 (based on a couple of Google searches), and the syntax checker is not extensible, so no extension would be able to make that go away. I've seen in a couple of places that you can turn off the error checking by turning off the PHP related code hints (Edit [Dreamweaver on Mac] -> Preferences -> Code Hints), but I've not tried that. Of course, if that works, then you'll get no code hints for variables and functions defined in your code, so not sure that will be a good trade off. On the other hand, Dreamweaver does report that code hinting may not work until syntax errors are corrected.
Dreamweaver CS5.5 Dynamic Code HInting PHP support is updated to PHP 5.3

Debugging PHP

I've been using xdebug to debug and understand code in php projects for a while now, and have sometimes come into situations where it's been unclear what's going on inside of PHP.
Is it possible to set xdebug or gdb up so that i can trace into actual php builtin functions?
If you are using a macosx, solaris or recent freebsd system you can throw a little dtrace at it. It can come in handy for those all too numerous "WTF is PHP doing?" moments.
I doubt it, xdebug is intended for tracing your PHP code, not the internals. The internals are assumed to be bug-free (which obviously they aren't sometimes, but that's beyond the scope of xdebug).
You can always look at the PHP source if you want to know what the built-in functions do, but that's sometimes pretty hairy. The PHP manual docs have always served me well enough when I want to know what they'll do.
You can use gdb to trace in to the C-level code, provided you have php compiled with debug symbols. Have a look here for a start:
http://derickrethans.nl/phps_segmentation_faults_gdbfu.php
One way to test the output of the Zend engine, to peek inside at the opcodes, you can use Derick Rethan's VLD (Vulcan Logic Dissasembler), which also appears to be on PECL. Note: only works on *nix systems (see site for requirements).
Some examples of debugging these opcodes can be found on Sara Golemon's blog, in articles such as Understanding Opcodes and How long is a piece of string?.
There is also great Google Chrome extension PHP Console with php library that allows to:
See errors & exception in Chrome JavaScript console & in notification popups.
Dump any type variable.
Execute PHP code remotely.
Protect access by password.
Group console logs by request.
Jump to error file:line in your text editor.
Copy error/debug data to clipboard (for testers).
Recommend to everyone!

PHP Console that doesn't require heavy installation or a desktop app?

I'm looking for clean way to break my current habit of using print commands in PHP when I want to see what's happening.
I am aware of options such as Zend Debugger but I use Coda for development and I'm not interested in mixing other software or having to do server commands. I just need a console that can be added to my codebase and then turned on/off.
Does anything like this exist? Furthermore, what do you use and why?
EDIT: There was a lot of stuff out there but I needed something even simpler so I ended up coding it myself. It didn't take long (nor is it very pretty) but I've put it up on my server for anyone else interested.
There is very good extension for Google Chrome - PHP Console.
You can use Xdebug in combination with any one of the many options available to view its debugging info.
There's FirePHP which will write your PHP log messages to the Firebug console.
I am aware of options such as Zend Debugger but I use Coda for development and I'm not interested in mixing other software or having to do server commands. I just need a console that can be added to my codebase and then turned on/off.
Not entirely sure if I understand you there, but couldn't you log to a file and then have a console window running with tail -f /path/to/log-file.txt? That works pretty well for me. Of course, you do need a console connection to the server for this.
Using Coda? That means you are using a mac. You probably want to look at XDebug and http://www.bluestatic.org/software/macgdbp/
There is another extension for Chrome available called ChromePHP. It's a little simpler than some of the other solutions:
https://chrome.google.com/webstore/detail/noaneddfkdjfnfdakjjmocngnfkfehhd
Getting started guide available at:
http://www.chromephp.com
During my development career i have not stumbled upon a software that displays the output you describe in your question. It would be a wonderful program or feature i believe but sadly i have not found any.
Like Andrew and nickf have answered, there are some good tools out there and until someone sits down and writes this, it looks like we are out in the cold.
I was looking for similar solution which wasn't heavy and even better I didn't need to include any classes, so I created simple function that outputs php to browser console, you can check it here:
Outputting PHP To Browser Console

Categories