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
180
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
140
Using Behat to test ExpressionEngine add-ons
boldminded
0
28
The Anatomy of a 5000 hour project
boldminded
4
770
Other Decks in Programming
See All in Programming
はしめてのプログラミングとロボット制御
watawatavoltage
0
290
Architectures with Lightweight Stores: New Rules and Options
manfredsteyer
PRO
0
100
スクラムマスターって孤独じゃないですか?
yoshitaroyoyo
1
140
Namespace on read
tagomoris
2
370
AHC035解説
terryu16
0
720
Google's Recipe for Scaling (Web) Security – LocoMocoSec 2024
lweichselbaum
0
170
CSC307 Lecture 08
javiergs
PRO
0
330
Findy - エンジニア向け会社紹介 / Findy Letter for Engineers
findyinc
2
81k
Play Billing Library 7.0.0 変更点まとめ@potatotips#88
kako351
0
160
OpenAI/Gemini APIを使って EPUBを翻訳するCLIツールをつくってみた
tomiyan
0
790
CSC307 Lecture 09
javiergs
PRO
1
500
AWS CDKにおける「再利用性」を考える / aws-cdk-reusability
gotok365
6
1.3k
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.4k
Fontdeck: Realign not Redesign
paulrobertlloyd
79
5.1k
Fireside Chat
paigeccino
25
2.8k
Gamification - CAS2011
davidbonilla
78
4.9k
Build The Right Thing And Hit Your Dates
maggiecrowley
28
2.2k
What's new in Ruby 2.0
geeforr
338
31k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
248
20k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
13
430
Into the Great Unknown - MozCon
thekraken
20
1.3k
It's Worth the Effort
3n
181
27k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
19k
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