Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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. legacy.joind.in/24817 @SammyK #phpworld Sammy Kaye Powers Dance The Washington, D.C.

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

  3. Thanks to Our Sponsors 2018

  4. legacy.joind.in/24817 @SammyK #phpworld Download the slides legacy.joind.in/24817

  5. legacy.joind.in/24817 @SammyK #phpworld Does not work for

  6. legacy.joind.in/24817 @SammyK #phpworld What is Debugging? Finding and fixing unexpected

    behavior in code
  7. So you write Some Code

  8. Does not work

  9. legacy.joind.in/24817 @SammyK #phpworld You could check the Error logs

  10. legacy.joind.in/24817 @SammyK #phpworld All the things var_dump()

  11. legacy.joind.in/24817 @SammyK #phpworld

  12. legacy.joind.in/24817 @SammyK #phpworld OR

  13. legacy.joind.in/24817 @SammyK #phpworld Use a ‘er

  14. legacy.joind.in/24817 @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. legacy.joind.in/24817 @SammyK #phpworld …now is the perfect time to learn

    Step Debugging BNEW! Professional
  16. legacy.joind.in/24817 @SammyK #phpworld Some step-debugging Jargon

  17. legacy.joind.in/24817 @SammyK #phpworld a signal that tells the debugger to

    pause the execution of your code Breakpoint
  18. legacy.joind.in/24817 @SammyK #phpworld run to the next breakpoint Resume Program

  19. legacy.joind.in/24817 @SammyK #phpworld advance to the next line in the

    same scope Step Over
  20. legacy.joind.in/24817 @SammyK #phpworld if the next line is a function

    call, enter the function Step Into
  21. legacy.joind.in/24817 @SammyK #phpworld run to the end of the current

    function Step Out
  22. legacy.joind.in/24817 @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. legacy.joind.in/24817 @SammyK #phpworld & Environment Setup

  24. legacy.joind.in/24817 @SammyK #phpworld

  25. legacy.joind.in/24817 @SammyK #phpworld https://xdebug.org/docs/remote Debug client (DBGp protocol)

  26. legacy.joind.in/24817 @SammyK #phpworld Setup

  27. #1 Start listening to debugging connections

  28. #2 Set a Breakpoint

  29. legacy.joind.in/24817 @SammyK #phpworld Done!

  30. legacy.joind.in/24817 @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. https://xdebug.org/docs/install Install +

  35. None
  36. legacy.joind.in/24817 @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. legacy.joind.in/24817 @SammyK #phpworld Start a session or CLI

  42. legacy.joind.in/24817 @SammyK #phpworld Query Param XDEBUG_SESSION_START

  43. legacy.joind.in/24817 @SammyK #phpworld Cookie XDEBUG_SESSION

  44. legacy.joind.in/24817 @SammyK #phpworld

  45. legacy.joind.in/24817 @SammyK #phpworld

  46. legacy.joind.in/24817 @SammyK #phpworld Env Variable export XDEBUG_CONFIG="idekey=foo" CLI

  47. legacy.joind.in/24817 @SammyK #phpworld Env Variable set XDEBUG_CONFIG="idekey=foo" CLI

  48. legacy.joind.in/24817 @SammyK #phpworld Don’t forget to unset set XDEBUG_CONFIG= unset

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

  50. legacy.joind.in/24817 @SammyK #phpworld Run some code! & CLI

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

  52. legacy.joind.in/24817 @SammyK #phpworld Built right into the CLI SAPI! $

    php -S
  53. legacy.joind.in/24817 @SammyK #phpworld

  54. legacy.joind.in/24817 @SammyK #phpworld learn? What did we

  55. legacy.joind.in/24817 @SammyK #phpworld +

  56. legacy.joind.in/24817 @SammyK #phpworld

  57. legacy.joind.in/24817 @SammyK #phpworld

  58. legacy.joind.in/24817 @SammyK #phpworld CLI

  59. legacy.joind.in/24817 @SammyK #phpworld Debugging In Action

  60. legacy.joind.in/24817 @SammyK #phpworld

  61. legacy.joind.in/24817 @SammyK #phpworld In production

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

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