Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Delicious Brains Blog:
How to Use Xdebug for Advanced PHP Debugging
Aug 07, 2017 @ 10:17:14

On the Delicious Brains site there's a tutorial posted that shows you how to use XDebug for advanced PHP debugging versus some of the usual practices of var_dump or print_r-ing your way through your testing.

You could just debug your PHP code using functions such as error_log, print, and var_dump, (and to be honest we’ve all done it, a lot!), but sometimes they just aren’t enough, and can actually slow you down while developing.

There must be a better way, surely?! Enter Xdebug, the rather awesome debugging and profiling tool for PHP.

In this post, I’ll take you through why Xdebug is amazing, getting it setup, how to use it, get the most out of it it, and some neat advanced uses all to make your life easier.

He starts with some background on his previous debugging practices and how discovering XDebug revolutionized his workflow. He then talks about breakpoints for debugging and what he calls "debug driven development". The article then walks you through the installation process and the integration with IDEs, specifically PHPStorm. The rest of the post shows examples of how to use XDebug along with breakpoints and IDE features to get more information about the current application state and where things are failing. He also includes sections about using XDebug for profiling and performing remote debugging via an SSH tunnel.

tagged: xdebug introduction debugging profiling tutorial setup ide integration

Link: https://deliciousbrains.com/xdebug-advanced-php-debugging/

Derick Rethans:
15 years of Xdebug
May 10, 2017 @ 10:27:14

In a recent post the fifteenth anniversary of the XDebug PHP debugging tool was celebrated and lead developer Derick Rethans was presented with several tokens of appreciation from the PHP community. In this new post to his site he shares the experience (it was a surprise after all) from his perspective and thanks those involved.

This article was going to be about some upcoming features in the 2.6 release. Or rather, I was hoping to announce at least a beta release of Xdebug 2.6. Unfortunately, I couldn't find enough time to work on all the issues that I wanted, although I've made a little progress.

What I can write about, is a little mystery.

He talks about the initial invite from James Titcumb to meet him at his favorite whisky store and the eight special bottles that the community purchased to show their appreciation for his hard fifteen years of work on this invaluable tool. He lists out the types for those interested and some of the messages from contributors showing their appreciation. He thanks all of those involved.

And on the Xdebug front, there are plenty of bugs to fix, features to add for Xdebug 2.6, and undoubtedly Dmitry will be "breaking" some things in PHP 7.2 that I need to support in Xdebug as well.
tagged: fifteen years anniversary derickrethans xdebug debugging tool project whiskey

Link: https://derickrethans.nl/xdebug-15.html

SitePoint PHP Blog:
Getting to Know and Love Xdebug
Apr 20, 2017 @ 17:55:59

On the SitePoint PHP blog editor Bruno Skvorc has posted a tutorial introducing you to Xdebug, the powerful debugging tool for PHP applications.

It’s been 15 years since Xdebug first came out. We think this is the perfect opportunity to re-introduce it to the world, and explain how and why it does what it does. Xdebug is a PHP extension (meaning it needs to be compiled and installed into a PHP installation) which provides the developer with some features for debugging.

It starts off by explaining some of the functionality that Xdebug brings to your debugging practices and the features that can help make it flow a little easier. It talks about how it differs from some of the IDE debugging tools and services like Blackfire.io. Next up is the example putting it to use and what the resulting errors look like. The post then gets into the integration of Vagrant with PhpStorm, using the profiler and how to force the rendering in Laravel output (it normally overrides the exception output with its own formatting).

tagged: tutorial know love xdebug introduction php debug debugging

Link: https://www.sitepoint.com/getting-know-love-xdebug/

PhpStorm Blog:
Working With PHPUnit and PhpStorm
Mar 23, 2017 @ 11:50:12

On the PhpStorm blog (from JetBrains) Gary Hockin reflects on a post from Adam Wathan with tips for combining PHPUnit and PhpStorm for more effective debugging.

Community stalwart and Laravel aficionado Adam Wathan blogged on his PHPUnit workflow in Sublime text.

Gary then goes through the points in Adam's post and shows how they can (mostly) be accomplished directly in PhpStorm:

  • Generating unit test boilerplate for a class
  • Using "snippets" to create shortcuts for reusable code
  • Running the tests in just one file directly from the IDE

Each section comes with a brief description and animated screen grabs showing the flow of the setup and use for each.

tagged: phpstorm debugging unittest feature generation snippets singlefile tutorial

Link: https://blog.jetbrains.com/phpstorm/2017/01/working-with-phpunit-and-phpstorm/

Freek Van der Herten:
Packages that make developing Laravel apps easier
Feb 13, 2017 @ 09:46:12

Freek Van der Herten has a new post to his site sharing what he considers some of the most helpful Laravel package to help with your debugging.

In this post I’d like to share some of the packages that make developing a Laravel app easier.

His list of packages includes a wide range of testing tools like:

For each item on his list he includes a screenshot of it in action (either of a terminal or a UI) and a brief explanation of how it can help.

tagged: framework help debugging package laravel development

Link: https://murze.be/2017/02/packages-make-developing-laravel-apps-easier/

Derick Rethans:
Good Bye PHP 5
Jan 11, 2017 @ 10:13:53

On his site Derick Rethans has posted an announcement about a major change in the Xdebug project (a widely used PHP debugger) he leads, saying goodby to PHP 5.

A few days ago I merged a patch into on GitHub. Maintaining PHP 5 and PHP 7 support in one code base is not particularly easy, and even more complicated for something like Xdebug, with its deep interactions with PHP's internals.

As PHP 5.6's active support has ended on December 31st, I also felt it no longer needed to support PHP 5 with Xdebug any more. It saves more than 5000 lines of code.

He shares some of the responses to the change (via Tweets) from the community ranging from full support to outcry over the change. He points out that the current version of Xdebug (2.5) will continue to operate on PHP 5 systems but when Xdebug 2.6 rolls around, the 2.5 branch will only receive bugfixes and no new features. You can find out about those upcoming features here.

tagged: xdebug debugging tool php7 php5 upgrade support

Link: https://derickrethans.nl/xdebug-php5.html

Laravel News:
Quickly Dumping Laravel Queries
Nov 28, 2016 @ 12:49:36

The Laravel News site has a quick post today with a helpful hint for those trying to track down exactly what queries their Laravel application is performing on database calls. In this post they show two ways to get this information - one using the Debugbar and the other with a quick script.

When you are building an application and utilizing Eloquent it’s very easy to hit the N+1 problem. This is where you select a model and then later use lazy loading to fetch child records.

They give an example of selecting a user, grabbing it's list of "posts" and then looping through them causing queries to fire for each post individually. A fix for it is using the "with" method to pre-load them but determining this could be tricky. Enter their two solutions: the Laravel Debugbar package and this quick script shared by magkopian that listens for a "kernel.handled" event and outputs the results of the "getQueryLog" method with the Laravel "dd" helper.

tagged: laravel dump queries debugbar debugging sql database tip

Link: https://laravel-news.com/2016/11/quickly-dumping-laravel-queries/

A better dd() for your TDD
Oct 13, 2016 @ 11:57:45

On the Tighten.co blog they have a recent post sharing a better dd() for your TDD - basically a better method for debugging the current state of object with a "dump and die" function.

An important part of every Laravel developer's debugging arsenal is the humble dd() helper function—"dump and die"—to output the contents of a variable and terminate execution of your code. In the browser, dd() results in a structured, easy-to-read tree, complete with little arrow buttons that can be clicked to expand or hide children of nested structures. In the terminal, however, it's a different story.

[...] Fortunately, it's simple to build your very own customized version of dd() to help tame your unwieldy terminal output—helping you find the details you're interested in quickly, without wearing out your trackpad (and your patience).

He provides two options you can use to help clean up the output of a "dump or die" method from the extensive results the current "dd" function provides:

Kint provides a few other helper methods you can use and easily configurable max and min depth to show in the output.

tagged: tdd testing vardumper kint library package output debugging

Link: https://blog.tighten.co/a-better-dd-for-your-tdd

Mark Baker:
PHP Generators – Sending “Gotchas”
Oct 11, 2016 @ 11:54:52

In this post to his site Mark Baker has shared some "sending gotchas" when generators are used in you PHP code. The focus of the article is on the "sending" part, pushing data into the generator for evaluation and use.

If you’re reading this, you’re probably already aware of just how useful PHP’s Generators are for improving performance and/or reducing memory overheads while keeping your code clean and easy to read.

Unlike their equivalent in some programming languages, PHP’s Generators allow you to send data into the Generator itself; not simply at initialisation (the arguments that we pass to the Generator when instantiating it); but also between iterations. This has its own uses, and again, allows us to move code from our main blocks and methods into the Generator itself. [...] However, there are a few “gotchas” when we combine Generators that both return and accept data in this way, and it really helps to be aware of them when we’re developing, otherwise it can create problems.

He starts simple, showing a generator that uses integers passed in as the starting number and addition interval for each loop. He gets a bit more complex in his next example, having a method called inside the loop. While the first instance of this behaves as expected, the second (after minor modification) yields unexpected results. He walks you through what's happening to produce those results and one possibility on how to get it corrected.

tagged: generator gotcha issue unexpected results debugging workaround

Link: https://markbakeruk.net/2016/10/08/php-generators-sending-gotchas/

Liip Blog:
Let’s debug in Drupal 8 !
Jun 20, 2016 @ 09:23:37

In a new post to the Liip blog Karine Chor shares some helpful Drupal 8 debugging tips and things you can do to determine what you code is doing "under the covers".

It has been nearly 7 months since Drupal 8 first release and as a developer, I am still in the learning process. It can be hard sometimes to know what is going wrong with your code and how to solve it. I will tell you about few things to know on how to develop and debug Drupal 8 projects and continue learning, learning and learning !

Her tips cover topics like:

  • Disabling cache
  • Displaying errors
  • Creating log messages
  • Debugging Twig templates
  • Profiling pages

The post ends with a section covering use of the the Drupal command line tool to provide even more real-time debugging functionality.

tagged: debugging drupal8 commandline cache error log twig profiler tutorial

Link: https://blog.liip.ch/archive/2016/06/20/lets-debug-drupal-8.html