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
Namespaces and Autoloading: Improving WordPress...
Search
Tom McFarlin
March 18, 2017
Programming
4
710
Namespaces and Autoloading: Improving WordPress Plugin Architecture
How to use namespaces and autoloading to improve your WordPress plugin architecture.
Tom McFarlin
March 18, 2017
Tweet
Share
More Decks by Tom McFarlin
See All by Tom McFarlin
A Case For Builing Web Applications in WordPress
tommcfarlin
0
23
Pressware, Publishing, and Passion
tommcfarlin
0
270
Personal Growth in Business and Development
tommcfarlin
0
350
The Truth About The Environment
tommcfarlin
0
1k
Other Decks in Programming
See All in Programming
GPUを計算資源として使おう!
primenumber
1
290
リバースエンジニアリング新時代へ! GhidraとClaude DesktopをMCPで繋ぐ/findy202507
tkmru
4
1.2k
AWS Summit Japan 2024と2025の比較/はじめてのKiro、今あなたは岐路に立つ
satoshi256kbyte
1
240
Android 16KBページサイズ対応をはじめからていねいに
mine2424
0
640
The Modern View Layer Rails Deserves: A Vision For 2025 And Beyond @ RailsConf 2025, Philadelphia, PA
marcoroth
2
780
テストから始めるAgentic Coding 〜Claude Codeと共に行うTDD〜 / Agentic Coding starts with testing
rkaga
16
6k
Claude Code + Container Use と Cursor で作る ローカル並列開発環境のススメ / ccc local dev
kaelaela
12
7.4k
可変変数との向き合い方 $$変数名が踊り出す$$ / php conference Variable variables
gunji
0
220
The Evolution of Enterprise Java with Jakarta EE 11 and Beyond
ivargrimstad
0
460
AIコーディングエージェント全社導入とセキュリティ対策
hikaruegashira
11
7.1k
Yes, You Can Work on Rails & any other Gem
kaspth
0
110
レベル1の開発生産性向上に取り組む − 日々の作業の効率化・自動化を通じた改善活動
kesoji
1
350
Featured
See All Featured
Automating Front-end Workflow
addyosmani
1370
200k
Code Review Best Practice
trishagee
69
19k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Designing for humans not robots
tammielis
253
25k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
760
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
990
YesSQL, Process and Tooling at Scale
rocio
173
14k
Gamification - CAS2011
davidbonilla
81
5.4k
Transcript
NAMESPACES AND AUTOLOADING Tom McFarlin | https://tommcfarlin.com | @tommcfarlin WordCamp
Atlanta 2017
HEY, WHAT’S UP? • I’m Tom (Nice to meet you)
• Suburbia Atlanta • Pressware • Life Outside WordPress
BUT ENOUGH ABOUT ME Let’s talk about you and code
and your code.
YOUR CODE • Namespaces • Autoloading • …Boring!
BUT ARE THEY REALLY? They sound boring.
THEY AREN’T BORING • Improved Code • Better Organization •
Increased Maintainability • Easier Debugging • More Money! (Maybe.) “Boring conversation anyway.”
WHAT ARE THEY? Oh! Money? (Not so boring anymore!)
WHAT ARE THEY? • Plugin conflicts • Weird warning messages
• Unable to activate a plugin • `class_exists` Namespaces
WHAT ARE THEY? • `include` • `include_once` • `require` •
`require_once` Autoloaders
NAMESPACES
The PHP Manual http://php.net/manual/en/language.namespaces.rationale.php “Namespaces are designed to solve two
problems that authors of libraries and applications encounter when creating re-usable code elements such as classes or functions…”
“A way to group related classes and interfaces having a
similar purpose.” WordCamp Atlanta 2017 A Working Definition
A PRACTICAL EXAMPLE • You’re working with files. • Classes
for reading, • Classes for writing, • You may have interfaces, • And so on.
None
None
NAMESPACE THAT CODE!
None
None
ON FILE ORGANIZATION • It’s not required; it helps. •
Logical Organization • Virtual Organization • Aim For Both. Please.
None
None
LET’S INSTANTIATE THEM! Wait, How?
NOTES ON NAMESPACES • You can’t just use `new.` •
Use the fully-qualified name. (The what?)
None
None
NOTES ON NAMESPACES • Aliasing with `use` • Place under
`namespace` • Now use the alias.
NOW LET’S INSTANTIATE THEM! That’s, How!
None
AUTOLOADING
The PHP Manual http://php.net/manual/en/language.oop5.autoload.php “The spl_autoload_register() function registers any number
of autoloaders, enabling for classes and interfaces to be automatically loaded if they are currently not defined. By registering autoloaders, PHP is given a last chance to load the class or interface before it fails with an error.”
“A way to automatically load interfaces and classes without using
include and require statements.” WordCamp Atlanta 2017 A Working Definition
A PRACTICAL EXAMPLE • Your files are organized. • You’re
ready to load them. • Let’s do it automatically! • Autoloading, right?
LET’S INSTANTIATE THEM! Wait, How?
WRITING AN AUTOLOADER • It’s not fully automated. • We
have to write it. • But once done, it’s done. • It can be reused!
ON AUTOLOADING • Where are the files? • How are
the files named? • Check if the file exists.
None
None
ON AUTOLOADING • Procedural • Object-oriented • `spl_autoload_register()`
STEPS FOR AN AUTOLOADER 1. Look at the argument 2.
Parse the namespace(s) 3. Is it an interface or a class? 4. Does the file exist? 5. Include the file.
WHERE TO FIND MORE • My Website • https://tommcfarlin.com •
SpeakerDeck • https://speakerdeck.com/tommcfarlin • GitHub • https://github.com/tommcfarlin
THANK YOU! Questions? Tom McFarlin | https://tommcfarlin.com | @tommcfarlin WordCamp
Atlanta 2017