Stop using var_dump(); Embrace step debugging

BoldMinded
October 09, 2017

Stop using var_dump(); Embrace step debugging

EE CONF 2017 Presentation

BoldMinded

October 09, 2017

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

44 slides
  1. 1

  2. Step debugging is stopping code execution on a specific line

    of code, then advancing the application 1 line of code at a time. 3
  3. var_dump($entry); die; object(BoldMinded\Publisher\Service\Entry\Entry) private 'request' => object(BoldMinded\Publisher\Service\Request) private 'siteId' =>

    int 1 private 'entryId' => null private 'defaultLanguage' => object(BoldMinded\Publisher\Model\Language) protected 'id' => int 1 protected 'short_name' => string 'en' (length=2) protected 'short_name_segment' => string 'en' (length=2) protected 'long_name' => string 'English' (length=7) protected 'locale' => string 'en_EN' (length=5) protected 'language_pack' => string 'english' (length=7) protected 'cat_url_indicator' => string 'category' (length=8) protected 'is_default' => string 'y' (length=1) protected 'is_enabled' => string 'y' (length=1) protected 'direction' => string 'ltr' (length=3) protected 'sites' => string '[1]' (length=3) protected '_name' => string 'publisher:Language' (length=18) 8
  4. Alternative function writeToFile($fileName, $data) { $file = PATH_CACHE.$fileName.'.txt'; $stream =

    fopen($file, 'a+'); fwrite($stream, print_r($data, TRUE) ."\n"); fclose($stream); } 11
  5. 13

  6. 14

  7. 16

  8. 22

  9. 23

  10. 24

  11. 25

  12. 27

  13. 28

  14. Useful breakpoint locations in EE — system/ee/legacy/libraries/Core.php function generate_page() —

    system/ee/EllisLab/Addons/channel/mod.channel.php function entries() — system/ee/legacy/libraries/Template.php function run_template_engine() 30
  15. Personal favorites — Call stack while debugging — Easier to

    debug loops — Can see EE template code at different parse states 31
  16. 32

  17. 34

  18. 35

  19. 36

  20. But You will gain that time back 10 fold when

    you're debugging. I promise. 40
  21. 42

More Decks by BoldMinded

Other Decks in Programming