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

Debug interactively PHP BLT #7

Debug interactively PHP BLT #7

046baac588d91fd78a85b189847a151d?s=128

Sota Sugiura

May 22, 2017
Tweet

Transcript

  1. Debug interactively @sota1235

  2. var_dump($sota1235); • @sota1235 • Call me ‘kirin’ • PHP &

    JavaScript • Mercari, Inc.
  3. http://sota1235.hatenablog.com/entry/2017/01/01/175228

  4. I did it

  5. Today’s theme

  6. Debug

  7. Debugging method • Using var_dump, echo • php -a •

    Writing tests • IDE • etc…
  8. Debugging method • Using var_dump, echo • php -a •

    Writing tests • IDE • etc…
  9. Using REPL (php -a) • Easy to use • Can

    load files • Good integration with CLI
  10. Is it the best way? • Bother to require autoloader

    • Reset state every time • Not good for many autoloader files…
  11. None
  12. psysh http://psysh.org/

  13. psysh • Rich CLI • Customizable • We can make

    own REPL
  14. Rich REPL • Auto complete (with Tab key) • Useful

    commands • history, documentation, show properties • Rich UI
  15. Customizable • We can place config file • ~/.config/psysh/psysh.php •

    We can do anything if PHP can
  16. <?php // Automatically autoload Composer dependencies if (is_file(getcwd() . '/vendor/autoload.php'))

    { require_once(getcwd() . '/vendor/autoload.php'); } Load composer automatically
  17. <?php // Use local config, if available if (is_file(getcwd() .

    '/.psysh.php')) { return require(getcwd() . '/.psysh.php'); } // Fall back to global config return [ 'startupMessage' => '<info>Using global config</info>', 'commands' => [ new \Psy\Command\ParseCommand, ], ]; Load local config
  18. <?php $default_includes = []; // Automatically autoload Composer dependencies if

    (is_file(getcwd() . '/vendor/autoload.php')) { $default_includes[] = getcwd() . '/vendor/autoload.php'); } if (array_pop(explode('/', getcwd())) === '') { $default_includes[] = getcwd() . 'lecacy_autoloader.php'; } return [ 'defaultIncludes' = $default_includes, ]; Legacy project? No problem☺
  19. Thank you