The debug dance: An intro to step debugging - ZendCon & OpenEnterprise 2018

The debug dance: An intro to step debugging - ZendCon & OpenEnterprise 2018

Talk given at ZendCon & OpenEnterprise (2018-10-16)

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.

8c090cc1ccd623a146ddd9159b1bf7e2?s=128

Sammy Kaye Powers

October 16, 2018
Tweet

Transcript

  1. joind.in/talk/5fb02 @SammyK #zcoe18 Sammy Kaye Powers Dance The Las Vegas,

    NV - 2018 An Intro To Step Debugging in
  2. joind.in/talk/5fb02 @SammyK #zcoe18 Download the slides joind.in/talk/5fb02

  3. joind.in/talk/5fb02 @SammyK #zcoe18 Does not work for

  4. joind.in/talk/5fb02 @SammyK #zcoe18 What is Debugging? Finding and fixing unexpected

    behavior in code
  5. So you write Some Code

  6. Does not work

  7. joind.in/talk/5fb02 @SammyK #zcoe18 You could check the Error logs

  8. joind.in/talk/5fb02 @SammyK #zcoe18 All the things var_dump()

  9. joind.in/talk/5fb02 @SammyK #zcoe18

  10. joind.in/talk/5fb02 @SammyK #zcoe18 OR

  11. joind.in/talk/5fb02 @SammyK #zcoe18 Use a ‘er

  12. joind.in/talk/5fb02 @SammyK #zcoe18 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++)
  13. joind.in/talk/5fb02 @SammyK #zcoe18 …now is the perfect time to learn

    Step Debugging BNEW! Professional
  14. joind.in/talk/5fb02 @SammyK #zcoe18 Some step-debugging Jargon

  15. joind.in/talk/5fb02 @SammyK #zcoe18 a signal that tells the debugger to

    pause the execution of your code Breakpoint
  16. joind.in/talk/5fb02 @SammyK #zcoe18 run to the next breakpoint Resume Program

  17. joind.in/talk/5fb02 @SammyK #zcoe18 advance to the next line in the

    same scope Step Over
  18. joind.in/talk/5fb02 @SammyK #zcoe18 if the next line is a function

    call, enter the function Step Into
  19. joind.in/talk/5fb02 @SammyK #zcoe18 run to the end of the current

    function Step Out
  20. joind.in/talk/5fb02 @SammyK #zcoe18 shows the execution path to the point

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

  22. joind.in/talk/5fb02 @SammyK #zcoe18

  23. joind.in/talk/5fb02 @SammyK #zcoe18 https://xdebug.org/docs/remote Debug client (DBGp protocol)

  24. joind.in/talk/5fb02 @SammyK #zcoe18 Setup

  25. #1 Start listening to debugging connections

  26. #2 Set a Breakpoint

  27. joind.in/talk/5fb02 @SammyK #zcoe18 Done!

  28. joind.in/talk/5fb02 @SammyK #zcoe18 Setup

  29. configured installed installed

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

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

    apt-get update $ apt-get install php7.2-xdebug
  32. https://xdebug.org/docs/install Install +

  33. None
  34. joind.in/talk/5fb02 @SammyK #zcoe18 Configure

  35. $ php --ini

  36. $ php --ini

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

  38. $ php -i | grep xdebug

  39. joind.in/talk/5fb02 @SammyK #zcoe18 Start a session or CLI

  40. joind.in/talk/5fb02 @SammyK #zcoe18 Query Param XDEBUG_SESSION_START

  41. joind.in/talk/5fb02 @SammyK #zcoe18 Cookie XDEBUG_SESSION

  42. joind.in/talk/5fb02 @SammyK #zcoe18

  43. joind.in/talk/5fb02 @SammyK #zcoe18

  44. joind.in/talk/5fb02 @SammyK #zcoe18 Env Variable export XDEBUG_CONFIG="idekey=foo" CLI

  45. joind.in/talk/5fb02 @SammyK #zcoe18 Env Variable set XDEBUG_CONFIG="idekey=foo" CLI

  46. joind.in/talk/5fb02 @SammyK #zcoe18 Don’t forget to unset set XDEBUG_CONFIG= unset

    XDEBUG_CONFIG when you’re done
  47. joind.in/talk/5fb02 @SammyK #zcoe18 alias debug-on='export XDEBUG_CONFIG="ide_key=foo"' alias debug-off='unset XDEBUG_CONFIG' Bash

    alias
  48. joind.in/talk/5fb02 @SammyK #zcoe18 Run some code! & CLI

  49. joind.in/talk/5fb02 @SammyK #zcoe18 PHP’s Built-in Web Server run locally using

  50. joind.in/talk/5fb02 @SammyK #zcoe18 Built right into the CLI SAPI! $

    php -S 127.0.0.1:8888
  51. joind.in/talk/5fb02 @SammyK #zcoe18

  52. joind.in/talk/5fb02 @SammyK #zcoe18 learn? What did we

  53. joind.in/talk/5fb02 @SammyK #zcoe18 +

  54. joind.in/talk/5fb02 @SammyK #zcoe18

  55. joind.in/talk/5fb02 @SammyK #zcoe18

  56. joind.in/talk/5fb02 @SammyK #zcoe18 CLI

  57. joind.in/talk/5fb02 @SammyK #zcoe18 Debugging In Action

  58. joind.in/talk/5fb02 @SammyK #zcoe18

  59. joind.in/talk/5fb02 @SammyK #zcoe18 In production

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

  61. Sammy Kaye Powers Thanks! /talk/5fb02 @SammyK SammyK.me Host of @PHPRoundtable