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

The Debug Dance - An Intro to Step Debugging - php[tek] 2017

The Debug Dance - An Intro to Step Debugging - php[tek] 2017

This talk was given at php[tek] 2017.

Using `var_dump()` to debug your app has its benefits, but there are more comprehensive and efficient ways to debug those particularly elusive bugs. Enter step debugging. We’ll be using 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.

Code examples: https://github.com/SammyK/debug-dance-php-tek-2017

Sammy Kaye Powers

May 26, 2017

More Decks by Sammy Kaye Powers

Other Decks in Programming


  1. joind.in/talk/a2b9a @SammyK #phptek Sammy Kaye Powers Dance The May 26th,

    2017 PHP[TEK] 2017 An Intro To Step Debugging in
  2. Thanks to our Sponsors!

  3. joind.in/talk/a2b9a @SammyK #phptek Download the examples & slides joind.in/talk/a2b9a

  4. joind.in/talk/a2b9a @SammyK #phptek Does not work for

  5. joind.in/talk/a2b9a @SammyK #phptek What is Debugging? Finding and fixing unexpected

    behavior in code
  6. So you write Some Code

  7. Does not work

  8. joind.in/talk/a2b9a @SammyK #phptek You could check the Error logs

  9. joind.in/talk/a2b9a @SammyK #phptek All the things var_dump()

  10. joind.in/talk/a2b9a @SammyK #phptek

  11. joind.in/talk/a2b9a @SammyK #phptek OR

  12. joind.in/talk/a2b9a @SammyK #phptek Use a ‘er

  13. joind.in/talk/a2b9a @SammyK #phptek 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++)
  14. joind.in/talk/a2b9a @SammyK #phptek …now is the perfect time to learn

    Step Debugging BNEW! Professional
  15. joind.in/talk/a2b9a @SammyK #phptek Some step-debugging Jargon

  16. joind.in/talk/a2b9a @SammyK #phptek a signal that tells the debugger to

    pause the execution of your code Breakpoint
  17. joind.in/talk/a2b9a @SammyK #phptek run to the next breakpoint Resume Program

  18. joind.in/talk/a2b9a @SammyK #phptek advance to the next line in the

    same scope Step Over
  19. joind.in/talk/a2b9a @SammyK #phptek if the next line is a function

    call, enter the function Step Into
  20. joind.in/talk/a2b9a @SammyK #phptek run to the end of the current

    function Step Out
  21. joind.in/talk/a2b9a @SammyK #phptek a live portal into the code execution

    process Debugging Console
  22. joind.in/talk/a2b9a @SammyK #phptek shows the execution path to the point

    where the code was paused Frames I… don’t have a cool drawing for “frames”…
  23. joind.in/talk/a2b9a @SammyK #phptek & Environment Setup

  24. joind.in/talk/a2b9a @SammyK #phptek Setup

  25. #1 Start listening to debugging connections

  26. #2 Set a Breakpoint

  27. joind.in/talk/a2b9a @SammyK #phptek Done!

  28. joind.in/talk/a2b9a @SammyK #phptek Setup

  29. configured installed installed

  30. $ brew tap homebrew/homebrew-php $ brew install php71 $ brew

    install php71-xdebug on Homebrew Install +
  31. $ add-apt-repository -y ppa:ondrej/php $ apt-get update $ apt-get install

    php7.1-xdebug on APT Install +
  32. https://xdebug.org/docs/install Install +

  33. None
  34. joind.in/talk/a2b9a @SammyK #phptek Configure

  35. $ php --ini

  36. $ sudo vi /usr/local/etc/php/ 7.1/conf.d/ext-xdebug.ini

  37. $ php -i | grep xdebug

  38. joind.in/talk/a2b9a @SammyK #phptek Start a session or CLI

  39. joind.in/talk/a2b9a @SammyK #phptek Query Param XDEBUG_SESSION_START

  40. joind.in/talk/a2b9a @SammyK #phptek Cookie XDEBUG_SESSION

  41. joind.in/talk/a2b9a @SammyK #phptek

  42. joind.in/talk/a2b9a @SammyK #phptek

  43. joind.in/talk/a2b9a @SammyK #phptek Env Variable export XDEBUG_CONFIG="idekey=foo" CLI

  44. joind.in/talk/a2b9a @SammyK #phptek Env Variable set XDEBUG_CONFIG="idekey=foo" CLI

  45. joind.in/talk/a2b9a @SammyK #phptek Don’t forget to unset set XDEBUG_CONFIG= unset

    XDEBUG_CONFIG when you’re done
  46. joind.in/talk/a2b9a @SammyK #phptek Run some code! & CLI

  47. joind.in/talk/a2b9a @SammyK #phptek PHP’s Built-in Web Server run locally using

  48. joind.in/talk/a2b9a @SammyK #phptek Built right into the CLI SAPI! $

    php -S
  49. joind.in/talk/a2b9a @SammyK #phptek

  50. joind.in/talk/a2b9a @SammyK #phptek learn? What did we

  51. joind.in/talk/a2b9a @SammyK #phptek +

  52. joind.in/talk/a2b9a @SammyK #phptek

  53. joind.in/talk/a2b9a @SammyK #phptek

  54. joind.in/talk/a2b9a @SammyK #phptek CLI

  55. joind.in/talk/a2b9a @SammyK #phptek Debugging In Action

  56. joind.in/talk/a2b9a @SammyK #phptek

  57. joind.in/talk/a2b9a @SammyK #phptek In production

  58. But wait! I have examples of other setups! & *

    (see me after class for more info)
  59. THANKS! SAMMY KAYE POWERS @SammyK SammyK.me Host of @PHPRoundtable @ChiPHPUG

    West Coast Swing Hire me! :) /talk/a2b9a I have stickers!