Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Stop using var_dump(); Embrace step debugging
Search
BoldMinded
October 09, 2017
Programming
0
190
Stop using var_dump(); Embrace step debugging
EE CONF 2017 Presentation
BoldMinded
October 09, 2017
Tweet
Share
More Decks by BoldMinded
See All by BoldMinded
A/B Testing
boldminded
0
150
Using Behat to test ExpressionEngine add-ons
boldminded
0
28
The Anatomy of a 5000 hour project
boldminded
4
790
Other Decks in Programming
See All in Programming
CSC509 Lecture 12
javiergs
PRO
0
160
Contemporary Test Cases
maaretp
0
130
CSC509 Lecture 09
javiergs
PRO
0
140
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
EventSourcingの理想と現実
wenas
6
2.3k
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
110
最新TCAキャッチアップ
0si43
0
140
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
Jakarta EE meets AI
ivargrimstad
0
530
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
A Tale of Four Properties
chriscoyier
156
23k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Why Our Code Smells
bkeepers
PRO
334
57k
Documentation Writing (for coders)
carmenintech
65
4.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
Bash Introduction
62gerente
608
210k
Building Applications with DynamoDB
mza
90
6.1k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Raft: Consensus for Rubyists
vanstee
136
6.6k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Transcript
1
Stop using var_dump(); embrace step debugging 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
{exp:channel:entries channel="foo" var_dump="yes" } {entry_id} {/exp:channel:entries} 4
{exp:channel:entries channel="foo"} ={title}={entry_id}={some_custom_field}= {/exp:channel:entries} 5
{exp:channel:entries channel="foo"} <pre>{entry_id}</pre> {/exp:channel:entries} 6
var_dump(); 7
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
Pros — Easy — No special tools necessary — Works
anywhere 9
Cons — Slow — Lacks context 10
Alternative function writeToFile($fileName, $data) { $file = PATH_CACHE.$fileName.'.txt'; $stream =
fopen($file, 'a+'); fwrite($stream, print_r($data, TRUE) ."\n"); fclose($stream); } 11
Xdebug is a PHP extension which provides debugging and profiling
capabilities. 12
13
14
Installing and Configuring apt-get install php-xdebug vim /etc/php/apache2/php.ini zend_extension=xdebug.so xdebug.remote_connect_back=1
xdebug.remote_autostart=0 xdebug.remote_enable=1 xdebug.show_exception_trace=1 15
16
Tools — PhpStorm — SublimeText w/ plugin ¯\_(ϑ)_/¯ — Microsoft
Code w/ plugin 17
Navigating — Setting breakpoints 18
Navigating — Conditional breakpoints 19
Navigating — Stepping over 20
Navigating — Stepping into 21
22
23
24
25
Tools — https://www.jetbrains.com/phpstorm/marklets/ — Xdebug Helper in Chrome Store —
?XDEBUG_SESSION_START=PHPSTORM 26
27
28
Demo <blink>Click Here!</blink> 29
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
Personal favorites — Call stack while debugging — Easier to
debug loops — Can see EE template code at different parse states 31
32
Remote step debugging zend_extension=xdebug.so xdebug.remote_connect_back=0 xdebug.remote_autostart=0 xdebug.remote_enable=1 33
34
35
36
Demo 37
Hark, there be dragons. 38
Truth You will inevitably lose productivity getting step debug working.
39
But You will gain that time back 10 fold when
you're debugging. I promise. 40
Tips Using repeatable scripts to configure environments will make things
easier. — Ansible — PuPHPet — Docker 41
42
Questions? 43
Thank You! — @litzinger — @boldminded — boldminded.com 44