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

QaFoo.com:
Never Use null
May 03, 2016 @ 13:07:32

On the QaFoo.com blog they've made a recommendation in their latest post - they suggest that you never use null.

When doing code reviews together with our customers we see a pattern regularly which I consider problematic in multiple regards – the usage of null as a valid property or return value. We can do better than this.

Let's go into common use cases first and then discuss how we can improve the code to make it more resilient against errors and make it simpler to use. Most issues highlighted are especially problematic when others are using your source code. As long as you are the only user (which hopefully is not the case) those patterns might be fine.

They talk about some of the most common uses they see for using null in PHP applications including setters for class properties (injection). They point out that in PHP 7 a missing value on a property would result in a Fatal error and make the functionality harder to test overall. They suggest that all required dependencies be injected on object construction instead, making it easier to know the current state of the object on testing. They also talk some about using null as a return value, how it could make debugging difficult and a solution that could make more sense - throwing an exception instead.

tagged: never use null return value injection setter solution suggestion debugging

Link: https://qafoo.com/blog/083_never_use_null.html

Adam Culp:
Using an SSH tunnel to step debug through a firewall
Apr 19, 2016 @ 10:54:28

Adam Culp has followed up some of his previous posts about the setup and configuration of remote debugging in PHP applications (more specifically in Zend Studio) with this new post. In it he shows how to use a SSH tunnel to allow debugging to happen through a firewall for those cases when direct access isn't possible.

In a previous post I covered how to set up step debugging in Zend Studio. But if that doesn’t work there may be a firewall in between the server and the debugging client, or IDE, preventing the connection. Here is a possible way to get around that.

He assumes that you already have the SSH server and connection available to you (he doesn't cover the install of that part). He then steps you through the setup of Zend Studio to add a new server, configure the SSH tunneling and remote/local ports to use. In his case he was using Zend Server so switching on debugging was as easy as turning in debugging via the toolbar. It's also worth noting that another popular PHP IDE can handle SSH-based debugging as well - PHPStorm - as seen here.

tagged: remote debugging ssh zendstudio setup configure tutorial phpstorm

Link: http://www.geekyboy.com/archives/1242

Adam Culp:
Setting up step debugging in Zend Studio
Apr 11, 2016 @ 11:52:43

Adam Culp has posted a guide on his site showing you how to set up debugging in Zend Studio, the PHP IDE from Zend. In it he walks you through the setup on both the server and client side to get them working happily together.

Recently I was helping someone set up step debugging in Zend Studio, and had some difficulties. Therefore I decided to create a blog post to remind me later, and perhaps help others get it set up.

I was doing this on an Ubuntu laptop, so while menus may vary slightly the process should be very similar. Also, I did this using a local virtual machine in VirtualBox, but using Bridged networking mode to simulate a remote server. In Zend Studio I had a project created with the Zend Framework Skeleton Application, and created a virtualhost in the virtual environment that mirrored that.

He starts with the server, pointing out that the only thing really needed there is an installed and working version of Xdebug. He then goes through each step in the IDE, complete with screenshots:

  • Configuring the server in the Preferences
  • Testing the connection between the two
  • Enabling debugging on the project
  • Ensuring the server is configured correctly to use debugging when specified

While some of his instructions are more specific to a Zend Server installation, they can still be mostly applied to any kind of system. You can also check the Xdebug documentation for additional help.

tagged: debugging zendstudio guide zendserver configuration testing xdebug

Link: http://www.geekyboy.com/archives/1220

Andreas Gohr:
Visualizing XDebug Traces
Feb 29, 2016 @ 12:49:44

Andreas Gohr has posted an interesting article to his site showing you how you can easily visualize XDebug stack traces and make them a bit more clear than the usual output dump.

As alluded to in yesterday's post, I'm currently hunting an elusive bug with xdebug. The problem is, that it only happens sporadically and when I know it happened it is too late to set a break point. So usual debugging methods don't work. Instead I want to use xdebug's execution tracing: let it log all function calls and then pick through the log when the bug occurs.

[...] To ease my debugging I looked for tools that could read the computer readable format. I found a few promising candidates, but in the end they either didn't work or they did not provide what I needed. So instead of hunting the bug, I built a tool

His tool takes in the XDebug output and turns it into something much more readable and properly nested.

tagged: tool library nested output trace stack debugging xdebug

Link: http://www.splitbrain.org/blog/2016-02/27-visualizing_xdebug_traces

PHP Roundtable:
034: Debugging is more than var_dump()
Nov 17, 2015 @ 11:09:48

The PHP Roundtable podcast, with host and PHP community member Sammy Kaye Powers, has posted their latest episode with a look at why "Debugging is more than var_dump()". In this episode Sammy is joined by Derick Rethans (of Xdebug fame), Colin O'Dell and Gary Hockin.

Believe it or not, there's a lot more to debugging your PHP code than var_dump()'ing all the things. We discuss how to use debugging tools to help us comprehensively debug our codebase.

You can watch the playback of the live recording of the episode either using the in-page video player or directly on YouTube. If you enjoy the episode be sure to subscribe to their feed and follow them on Twitter to get information about new episodes as they're released and when future live recordings are happening.

tagged: phproundtable ep34 debugging vardump tools podcast

Link: https://www.phproundtable.com/episode/debugging-is-more-than-var-dump

SitePoint PHP Blog:
Debugging WordPress on Azure with Z-Ray
Oct 13, 2015 @ 11:23:55

On the SitePoint PHP blog there's a tutorial showing you how to integrate the Z-Ray tool into WordPress to make debugging it on an Azure instance simpler. The steps make major use of the Azure control panel handling, so it's not quite as useful as a cross-platform guide but at least it gives you an idea of what you could expect from the Z-Ray+WordPress integration.

We all know that WordPress is an amazingly rich, extendable and simple platform. That’s probably one of the reasons it powers so much of the web today. But in some cases this richness can be the downfall of your site. [...] This means you need an easy, safe and reliable way to profile your WordPress app that will help you identify the bottlenecks slowing it down.

This article demonstrates a simple way to do just this. It describes how to debug a WordPress application deployed on Microsoft Azure’s web app service, using Z-Ray for Azure – a new technology that was announced a few months ago and is now in preview mode.

He walks you through the entire process (assuming you already have an account on Azure:

  • Creating the sample WordPress application on Azure
  • Enabling Z-Ray
  • Developing WordPress with Z-Ray

In that last step he includes some screenshots of the kinds of results you can expect from the plugin including details about cache objects, plugin statistics, hooks being executed and WP Query use. He ends the post looking at using Z-Ray for mobile debugging and how to use it in "secured mode" in a production environment.

tagged: tutorial wordpress azure microsoft zray debugging installation configuration

Link: http://www.sitepoint.com/debugging-wordpress-on-azure-with-z-ray/

7PHP.com:
#DC4D Brings You Debugging Beyond The var_dump() Approach
Sep 15, 2015 @ 09:52:34

The 7PHP.com site has posted another in its series of spotlights on people and happenings in the PHP community. In this latest edition he talks with Cal Evans about the latest Day Camp 4 Developers evening happening Friday, September 18th: "Debugging Beyond var_dump()".

Day Camp 4 Developers is a virtual ‘mini’ PHP conference. Meaning you can watch in realtime 5 awesome speakers, talking about some cool quality stuffs, while you are comfortably seated on your sofa with your snacks and beverages. [...] It’s a new week on our PHP Calendar, specially in our Virtual PHP calendar – it’s THE week for DC4D which will be held on this upcoming Friday 18th Sept 2015 – see it all here, click! One very important thing to know, DC4D is heartily brought forward by our PHP Icon – the one and only Mr Cal Evans, together with his wife, The Lovely & Talented Kathy.

Cal answers questions about the event including:

  • How it all started
  • How he finds the speakers for the theme for each event
  • Some of the things he's learned from putting on the event

The interview also includes a bonus Q&A with one of the speakers, Joshua Thijssen. They talk about Joshua's motivation behind the talk, one things that people will learn from it and what he sees as the benefit of a live presentation vs recorded.

tagged: daycamp4developers 7php interview calevans joshuathijssen vardump debugging

Link: http://7php.com/dc4d-debugging/

Community News:
Day Camp 4 Developers - Debugging Beyond var_dump()
Jul 14, 2015 @ 08:50:14

The Day Camp 4 Developers online "conference" has officially announced their latest event, "Debugging Beyond var_dump()", happening Friday September 18th from 9am through 3pm (CST). This time around they're putting it on with the help of the fine folks at php[architect] too.

This latest edition of the excellent event features several well known speakers talking about debugging tips and sharing tools that can make you a more effective developer:

  • "PHP Profiling, an Introduction" (Fabien Potencier)
  • "Debugging: Past, Present and Future" (Derick Rethans)
  • "Characterization Testing for Legacy Applications" (Paul M. Jones)
  • "Modern Tools for API Debugging and Testing" (Neil Mansilla)
  • "Don't Reboot, Debug!" (Joshua Thijssen)

Much like it's siblings, the Day Camp 4 Developers event is completely virtual and is held via a webcast. Tickets will soon be sale and, compared to the usual cost of a conference ticket, are quite cheap. There's even group tickets available if you'd like to hold a "watch party" in your office.

Check out the Day Camp 4 Developers site for more information or to pick up your tickets!

tagged: daycamp4developer debugging vardump fabienpotencier derickrethans pauljones neilmansalla joshuathijssen

Link: http://daycamp4developers.com/

Gary Hockin:
Debugging PHP Command Line (with PHPStorm and XDebug)
May 07, 2015 @ 11:47:09

Gary Hockin has a recent post showing how you can debug PHP HTTP requests from the command line using PHPStorm and XDebug. These instructions aren't specific to PHPStorm, however. They can be used in any IDE/editor that supports remote XDebug connections.

At PHP North West I had huge difficulties configuring Xdebug and both my PHP and PHP Storm so they play nice in a CLI environment. So here, for others and almost certainly my future self, is how to do it.

He goes through each step of the setup process assuming that you already have the necessary software installed. He shows how to configure XDebug for remote debugging in the ini configuration, setting up PHPStorm to receive the connection and, finally, adding the "XDEBUG_CONFIG" environment variable to tell PHP to relay the requests back to your waiting IDE.

tagged: remote debugging phpstorm commandline xdebug configure setup environment

Link: http://blog.hock.in/2015/05/04/debugging-php-command-line-with-php-storm/

Derick Rethans:
Xdebug 2.3: Improvements to Debugging
Mar 25, 2015 @ 09:13:34

In the latest in his series covering some of the improvements in the latest Xdebug release, Derick Rethans has posted this new article detailing some of the performance enhancements related to remote debugging that come with this new version.

This is the fourth article in a series about new features in Xdebug 2.3, which was first released on February 22nd. In this article we are looking at the improvements towards "remote" debugging.

The updates include showing the values of user-defined constants, being able to set an exception breakpoint on all exceptions and additional features around debugging the exceptions themselves. The output now includes the exception's error code and which exception the flow was broken on (though in his example of PHPStorm, the IDE won't report that information back). The last change he mentions is a change that reverts the output to a log if it can't write to a socket (usually SELinux related).

tagged: xdebug performance improvement remote debugging version release

Link: http://derickrethans.nl/xdebug-2.3-debugging-improvements.html