I'm a bit spoiled on ruby and am used to using the amazing pry
facilities for apps. I'll lock an app down to 1 thread and then let pry pop open in the httpd console and then be able to get to the bottom of a lot of issues, however I am not finding anything quite like this available in PHP. Is there a similar or accepted solution that works like this for PHP for debugging and tracing out data structures, etc. during execution?

- 12,102
- 17
- 78
- 152
-
Almost a duplicate of [REPL for PHP](http://stackoverflow.com/questions/5764304/is-there-a-better-console-for-php-than-running-in-interactive-mode), which doesn't ask for interactive debugging. – Chris Wesseling Apr 24 '14 at 14:12
5 Answers
I know exactly what you mean. I missed Pry after moving to PHP as well. So far PsySH looks like the best REPL for PHP that is the most like Pry. It has reflection, so you can use commands like ls
to evaluate the variables, constants, classes, etc. It has a help command, similar to Pry's show-doc
that allows you to read documentation on functions or object properties. You can even view the source of any object, just like Pry's show-source
command. Also debugging:
"PsySH can be used as an interactive debugger, much like JavaScript's debugger statement, saving you from endless var_dump() and die() iterations. Just drop this line in where you'd like to have a breakpoint:
\Psy\Shell::debug(get_defined_vars());"
Boris is also another good REPL for PHP that is similar to Pry.

- 1,755
- 20
- 31
-
2Absolutely excellent find. Really appreciate your sharing of this as it is a much better solution than anything else has assumed or found so far. – ylluminate Apr 24 '14 at 15:51
-
2No problem. I was glad to find it myself. Pry is an excellent tool that we take for granted in the Ruby community. Looking for a good REPL like Pry was one of the first things I did when I started learning PHP. – Adam Apr 24 '14 at 18:40
-
1No kidding. I'm glad I moved back away from PHP a few months ago. We had to use PHP for a bit this past year for several months on a couple large projects (previously I'd used it for a few years), but given a few issues, we decided to go back to being a ruby shop. We're back to moving at warp speed. Nonetheless, this is good to know for sure in case anything arises! We all could use any help possible when building our php houses of cards... ;) – ylluminate Apr 24 '14 at 18:54
-
Cool. Yeah, it's always good to know that you will have good tools at your disposal no matter what language you choose! – Adam Apr 24 '14 at 20:04
Yeah. Called dephpugger
https://github.com/tacnoman/dephpugger
You start the server in terminal and debugger too. The commands are similar, n to next, c to continue, etc...

- 792
- 1
- 7
- 27
-
I never used PsySH. But Dephpugger is equals to byebug for ruby or ipdb for python. You can install easy too. – Renato Cassino Mar 18 '17 at 20:09
I'm not really into Ruby and pry but as far as i have read into the topic pry is a debugtool. For debugging php I use a local webserver called wamp with the built in xDebug. In combination with the IDE : Netbeans or Eclipse you can look into datastructures/objects during execution of your php script.

- 129
- 1
- 1
- 11
-
Sure, I'm familiar with xdebug, and we use it, but we just would prefer something more "pry-like" as there is so much power in its methodologies and the quick way you can leverage it in the shell while debugging. – ylluminate May 02 '13 at 23:37
PHP works differently from Ruby, it's kind of hard to compare within the context you are asking about.
Inspecting complex structures within runtime is done in PHP via debugging, which means that client debug side (= PHP IDE) must be able to communicate with server debug side running PHP (this is usually done by initiating cookie with special name, e.g. via URL DBGSESSID=123&dbgParam1=123).
So PHP on the web server must have special debugging module installed (like XDebug) and when debugging-client says "stop now", then web server pauses execution at certain breakpoint exposing any local, global, static etc.. data structures.
If interested, take a look at available PHP IDEs with support for debugging: What is the best IDE for PHP?