$30 off During Our Annual Pro Sale. View Details »

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
Tweet

More Decks by Sammy Kaye Powers

Other Decks in Programming

Transcript

  1. joind.in/talk/a2b9a
    @SammyK #phptek
    Sammy Kaye Powers
    Dance
    The
    May 26th, 2017
    PHP[TEK] 2017
    An Intro To
    Step Debugging in

    View Slide

  2. Thanks to our
    Sponsors!

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  6. So you write
    Some Code

    View Slide

  7. Does not work

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  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++)

    View Slide

  14. joind.in/talk/a2b9a
    @SammyK #phptek
    …now is the perfect time to learn
    Step Debugging
    BNEW!
    Professional

    View Slide

  15. joind.in/talk/a2b9a
    @SammyK #phptek
    Some step-debugging
    Jargon

    View Slide

  16. joind.in/talk/a2b9a
    @SammyK #phptek
    a signal that tells the debugger to pause the execution of your code
    Breakpoint

    View Slide

  17. joind.in/talk/a2b9a
    @SammyK #phptek
    run to the next breakpoint
    Resume Program

    View Slide

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

    View Slide

  19. joind.in/talk/a2b9a
    @SammyK #phptek
    if the next line is a function call, enter the function
    Step Into

    View Slide

  20. joind.in/talk/a2b9a
    @SammyK #phptek
    run to the end of the current function
    Step Out

    View Slide

  21. joind.in/talk/a2b9a
    @SammyK #phptek
    a live portal into the code execution process
    Debugging Console

    View Slide

  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”…

    View Slide

  23. joind.in/talk/a2b9a
    @SammyK #phptek
    &
    Environment
    Setup

    View Slide

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

    View Slide

  25. #1
    Start listening to
    debugging connections

    View Slide

  26. #2
    Set a
    Breakpoint

    View Slide

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

    View Slide

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

    View Slide

  29. configured
    installed
    installed

    View Slide

  30. $ brew tap homebrew/homebrew-php
    $ brew install php71
    $ brew install php71-xdebug
    on
    Homebrew
    Install +

    View Slide

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

    View Slide

  32. https://xdebug.org/docs/install
    Install +

    View Slide

  33. View Slide

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

    View Slide

  35. $ php --ini

    View Slide

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

    View Slide

  37. $ php -i | grep xdebug

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  46. joind.in/talk/a2b9a
    @SammyK #phptek
    Run some code!
    &
    CLI

    View Slide

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

    View Slide

  48. joind.in/talk/a2b9a
    @SammyK #phptek
    Built right into the CLI SAPI!
    $ php -S 127.0.0.1:8888

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  58. But wait!
    I have examples of other setups!
    &
    * (see me after class for more info)

    View Slide

  59. THANKS!
    SAMMY KAYE POWERS
    @SammyK
    SammyK.me
    Host of @PHPRoundtable
    @ChiPHPUG
    West Coast Swing
    Hire me! :)
    /talk/a2b9a
    I have
    stickers!

    View Slide