Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Namespaces and Autoloading: Improving WordPress...
Search
Tom McFarlin
March 18, 2017
Programming
780
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Namespaces and Autoloading: Improving WordPress Plugin Architecture
How to use namespaces and autoloading to improve your WordPress plugin architecture.
Tom McFarlin
March 18, 2017
More Decks by Tom McFarlin
See All by Tom McFarlin
A Case For Builing Web Applications in WordPress
tommcfarlin
0
42
Pressware, Publishing, and Passion
tommcfarlin
0
280
Personal Growth in Business and Development
tommcfarlin
0
430
The Truth About The Environment
tommcfarlin
0
1.2k
Other Decks in Programming
See All in Programming
R8 の設定見直しでアプリサイズ削減
andpad
0
140
phperだってパンチカードでコーディングしたい
o0h
PRO
0
210
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
280
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
260
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
120
Simple Storage Service(S3) is not simple
iwatsukayura
0
190
カツオ、ご期待ください
suneo3476
0
150
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
620
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
470
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
390
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
140
すこし踏み込む CancellationToken
htkym
2
1.6k
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
530
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
310
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
260
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
610
Code Review Best Practice
trishagee
74
20k
Chasing Engaging Ingredients in Design
codingconduct
0
340
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
1.1k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Building AI with AI
inesmontani
PRO
1
1.3k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
620
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