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
740
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
32
Pressware, Publishing, and Passion
tommcfarlin
0
280
Personal Growth in Business and Development
tommcfarlin
0
370
The Truth About The Environment
tommcfarlin
0
1.1k
Other Decks in Programming
See All in Programming
AI前提で考えるiOSアプリのモダナイズ設計
yuukiw00w
0
210
[AtCoder Conference 2025] LLMを使った業務AHCの上⼿な解き⽅
terryu16
6
1k
LLMで複雑な検索条件アセットから脱却する!! 生成的検索インタフェースの設計論
po3rin
4
1.1k
メルカリのリーダビリティチームが取り組む、AI時代のスケーラブルな品質文化
cloverrose
2
440
re:Invent 2025 のイケてるサービスを紹介する
maroon1st
0
160
ローカルLLMを⽤いてコード補完を⾏う VSCode拡張機能を作ってみた
nearme_tech
PRO
0
230
ゲームの物理 剛体編
fadis
0
390
ThorVG Viewer In VS Code
nors
0
530
チームをチームにするEM
hitode909
0
430
Cell-Based Architecture
larchanjo
0
160
Findy AI+の開発、運用におけるMCP活用事例
starfish719
0
2k
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
590
Featured
See All Featured
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
1.8k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
280
How to train your dragon (web standard)
notwaldorf
97
6.5k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.2k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
0
33
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
130
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
33
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.5k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
61
47k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.3k
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