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
760
4
Share
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
40
Pressware, Publishing, and Passion
tommcfarlin
0
280
Personal Growth in Business and Development
tommcfarlin
0
380
The Truth About The Environment
tommcfarlin
0
1.1k
Other Decks in Programming
See All in Programming
tRPCの概要と少しだけパフォーマンス
misoton665
2
250
書き換えて学ぶTemporal #fukts
pirosikick
1
290
Programming with a DJ Controller — not vibe coding
m_seki
3
660
Agentic Elixir
whatyouhide
0
420
CursorとClaudeCodeとCodexとOpenCodeを実際に比較してみた
terisuke
1
510
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
310
2026-04-15 Spring IO - I Can See Clearly Now
jonatan_ivanov
1
140
決定論 vs 確率論:Gemini 3 FlashとTF-IDFを組み合わせた「法規判定エンジン」の構築
shukob
0
140
JOAI2026 1st solution - heron0519 -
heron0519
0
160
運転動画を検索可能にする〜Cosmos-Embed1とDatabricks Vector Searchで〜/cosmos-embed1-databricks-vector-search
studio_graph
1
520
AWSコミュニティ活動は顧客のクラウド推進に効くのか / Do AWS community activities help customers adopt the cloud?
seike460
PRO
0
160
ふりがな Deep Dive try! Swift Tokyo 2026
watura
0
250
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
42
3k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
52k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
23k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.7k
Leo the Paperboy
mayatellez
7
1.7k
Automating Front-end Workflow
addyosmani
1370
200k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
290
Paper Plane (Part 1)
katiecoart
PRO
0
6.9k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.4k
HDC tutorial
michielstock
2
640
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
490
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
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