The Debug Dance - An Intro To Step Debugging - php[world] 2018

The Debug Dance - An Intro To Step Debugging - php[world] 2018

This talk was given at php[world] 2018.

Using `var_dump()` to debug your app has its benefits, but there are more comprehensive and efficient ways to debug those particularly illusive bugs. Enter step debugging. We'll be using Xdebug & the PhpStorm IDE to step through our PHP apps line by line and see how much more power step debugging gives us over the conventional `var_dump()` technique. We'll also touch on debugging from the command line. Learn to dance in PHP with step debugging.


Sammy Kaye Powers

November 14, 2018


  1. @SammyK #phpworld Sammy Kaye Powers Dance The Washington, D.C.

    - 2018 An Intro To Step Debugging in
  2. @SammyK #phpworld CLOSER :) Get

  3. Thanks to Our Sponsors 2018

  4. @SammyK #phpworld Download the slides

  5. @SammyK #phpworld Does not work for

  6. @SammyK #phpworld What is Debugging? Finding and fixing unexpected

    behavior in code
  7. So you write Some Code

  8. Does not work

  9. @SammyK #phpworld You could check the Error logs

  10. @SammyK #phpworld All the things var_dump()

  11. @SammyK #phpworld

  12. @SammyK #phpworld OR

  13. @SammyK #phpworld Use a ‘er

  14. @SammyK #phpworld Kate Gregory “ I'm not saying, ‘don't

    use printf()’, [...] but I think it's insane to use printf() on day one of learning C++. [...] I would first say use the debugger. Episode 30: Stop Teaching C (When Teaching C++)
  15. @SammyK #phpworld …now is the perfect time to learn

    Step Debugging BNEW! Professional
  16. @SammyK #phpworld Some step-debugging Jargon

  17. @SammyK #phpworld a signal that tells the debugger to

    pause the execution of your code Breakpoint
  18. @SammyK #phpworld run to the next breakpoint Resume Program

  19. @SammyK #phpworld advance to the next line in the

    same scope Step Over
  20. @SammyK #phpworld if the next line is a function

    call, enter the function Step Into
  21. @SammyK #phpworld run to the end of the current

    function Step Out
  22. @SammyK #phpworld shows the execution path to the point

    where the code was paused Frames I… don’t have a cool drawing for “frames”…
  23. @SammyK #phpworld & Environment Setup

  24. @SammyK #phpworld

  25. @SammyK #phpworld Debug client (DBGp protocol)

  26. @SammyK #phpworld Setup

  27. #1 Start listening to debugging connections

  28. #2 Set a Breakpoint

  29. @SammyK #phpworld Done!

  30. @SammyK #phpworld Setup

  31. configured installed installed

  32. on Homebrew Install + $ brew install php $ pecl

    install xdebug
  33. on APT Install + $ add-apt-repository -y \ ppa:ondrej/php $

    apt-get update $ apt-get install php7.2-xdebug
  34. Install +

  35. None
  36. @SammyK #phpworld Configure

  37. $ php --ini

  38. $ php --ini

  39. $ sudo vi /usr/local/etc/php/ 7.2/conf.d/ext-xdebug.ini

  40. $ php -i | grep xdebug

  41. @SammyK #phpworld Start a session or CLI

  42. @SammyK #phpworld Query Param XDEBUG_SESSION_START

  43. @SammyK #phpworld Cookie XDEBUG_SESSION

  44. @SammyK #phpworld

  45. @SammyK #phpworld

  46. @SammyK #phpworld Env Variable export XDEBUG_CONFIG="idekey=foo" CLI

  47. @SammyK #phpworld Env Variable set XDEBUG_CONFIG="idekey=foo" CLI

  48. @SammyK #phpworld Don’t forget to unset set XDEBUG_CONFIG= unset

    XDEBUG_CONFIG when you’re done
  49. @SammyK #phpworld alias debug-on='export XDEBUG_CONFIG="ide_key=foo"' alias debug-off='unset XDEBUG_CONFIG' Bash

  50. @SammyK #phpworld Run some code! & CLI

  51. @SammyK #phpworld PHP’s Built-in Web Server run locally using

  52. @SammyK #phpworld Built right into the CLI SAPI! $

    php -S
  53. @SammyK #phpworld

  54. @SammyK #phpworld learn? What did we

  55. @SammyK #phpworld +

  56. @SammyK #phpworld

  57. @SammyK #phpworld

  58. @SammyK #phpworld CLI

  59. @SammyK #phpworld Debugging In Action

  60. @SammyK #phpworld

  61. @SammyK #phpworld In production

  62. But wait! * (see me after class for more info)

  63. Sammy Kaye Powers Thanks! /24817 @SammyK Host of @PHPRoundtable