Interactive PHP Debugging with PsySH

Posted by Unknown on Monday, September 29, 2014

It’s 1:00 a.m., the deadline for your web application’s delivery is in 8 hours… and it’s not working. As you try to figure out what’s going on, you fill your code with var_dump() and die() everywhere to see where the bug is…


You are annoyed. Every time you want to try out a return value or variable assignment, you have to change your source code, execute your application, and see the results… In the end, you are unsure of whether or not you’ve removed all those var_dumps from the code. Is this situation familiar to you?


PsySH to the rescue


PsySH is a Read-Eval-Print Loop (or REPL). You may have used a REPL before via your browser’s javascript console. If you have, you know that it possesses a lot of power and can be useful while debugging your JS code.


Talking about PHP, you might have used PHP’s interactive console (php -a) before. There, you can write some code and the console will execute it as soon as you press enter:



$ php -a
Interactive shell

php
> $a = 'Hello world!';
php
> echo $a;
Hello world!
php
>


Unfortunately, the interactive shell is not a REPL since it lacks the “P” (print). I had to execute an echo statement to see the contents of $a. In a true REPL, we would have seen it immediately after assigning the value to it.


Continue reading %Interactive PHP Debugging with PsySH%




more

{ 0 comments... » Interactive PHP Debugging with PsySH read them below or add one }

Post a Comment

Popular Posts