Leanpub Header

Skip to main content

PHP: The "Right" Way

Your guide to PHP best practices, coding standards, and authoritative tutorials.

New to PHP? Coming back to PHP after a hiatus? Been writing PHP for a decade? Whatever your level, you'll learn something here. 

The authors are letting you choose the price you pay for this book!

Pick Your Price...
PDF
EPUB
WEB
44,330
Readers
89
Pages
22,664Words
About

About

About the Book

There’s a lot of outdated information on the Web that leads new PHP users astray, propagating bad practices and insecure code. PHP: The Right Way is an easy-to-read, quick reference for PHP popular coding standards, links to authoritative tutorials around the Web and what the contributors consider to be best practices at the present time.

There is no canonical way to use PHP. This book aims to introduce new PHP developers to some topics which they may not discover until it is too late, and aims to give seasoned pros some fresh ideas on those topics they’ve been doing for years without ever reconsidering. This ebook will also not tell you which tools to use, but instead offer suggestions for multiple options, when possible explaining the differences in approach and use-case.

This is a living document and will continue to be updated with more helpful information and examples as they become available.

Share this book

Categories

License

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

Price

Pick Your Price...

Minimum price

Free!

$7.99

You pay

$0.00

Causes get

$0.00
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 0)

0
The author will earn $0.00 from your purchase!
You can get credits monthly with a Reader Membership

Author

About the Authors

Phil Sturgeon

Since 2010 I've worked as a freelancer, consultant, API lead, and CTO for several API-centric technology startups. Working as an internal API consultant for WeWork gave me a lot to write about, where I used my experience of things going horribly horribly wrong to help educate developers, define standards for API design and architecture, and implementing full API design lifecycles so we weren't all just building nonsense and hoping it was useful.

Trying to get loads of different questionably built APIs tidied up, playing nicely, and working quickly was a constant source of learning for me and everyone involved. I took a lot of that learning to Stoplight, and helped plan, build, and manage most of your favourite OpenAPI tools.

When I'm not banging on about APIs I'm riding, racing, or crashing various bikes, or saving the plant through Protect Earth, an environmental charity I co-founded in 2020. We create brand new woodlands, restore and extend ancient woodlands, and run around with machetes getting rid of invasive species.

Leanpub Podcast

Episode 292

An Interview with Phil Sturgeon

Josh Lockhart

Creator of the Slim Framework and PHP The Right Way. Senior developer at New Media Campaigns.

Contents

Table of Contents

1.Language Highlights

  1. 1.1Xdebug
  2. 1.2Command Line Interface
  3. 1.3Standard PHP Library
  4. 1.4Programming Paradigms
  5. 1.5Namespaces
  6. 1.6Windows Setup
  7. 1.7macOS Setup
  8. 1.8Linux Setup

2.Getting Started

  1. 2.1Common Directory structure
  2. 2.2Use the Current Stable Version (8.4)
  3. 2.3Built-in web server
  4. 2.4Complementary Testing Tools
  5. 2.5Test Driven Development

3.Testing

  1. 3.1Behavior Driven Development
  2. 3.2Complex Problem

4.Dependency Injection

  1. 4.1Containers
  2. 4.2Basic Concept
  3. 4.3Further Reading
  4. 4.4Data Filtering
  5. 4.5Web Application Security
  6. 4.6Error Reporting
  7. 4.7Configuration Files
  8. 4.8Register Globals

5.Security

  1. 5.1Password Hashing
  2. 5.2Further Reading
  3. 5.3Benefits
  4. 5.4Compiled Templates
  5. 5.5Plain PHP Templates

6.Templating

  1. 6.1Working with UTF-8

7.Coding Practices

  1. 7.1The Basics
  2. 7.2Design Patterns
  3. 7.3Internationalization (i18n) and Localization (l10n)
  4. 7.4Common ways to implement
  5. 7.5Gettext
  6. 7.6Date and Time
  7. 7.7PEAR
  8. 7.8Composer and Packagist

8.Dependency Management

  1. 8.1Books
  2. 8.2People to Follow
  3. 8.3Other Useful Resources
  4. 8.4Video Tutorials
  5. 8.5Components
  6. 8.6PHP PaaS Providers

9.Resources

  1. 9.1Frameworks
  2. 9.2From the Source

10.Errors and Exceptions

  1. 10.1Errors
  2. 10.2Exceptions

11.Caching

  1. 11.1Object Caching
  2. 11.2Opcode Cache
  3. 11.3Virtual or Dedicated Servers
  4. 11.4Shared Servers

12.Servers and Deployment

  1. 12.1Platform as a Service (PaaS)
  2. 12.2Building and Deploying your Application
  3. 12.3Docker
  4. 12.4Vagrant

13.Virtualization

14.Code Style Guide

15.Community

  1. 15.1PHP Conferences
  2. 15.2PHP User Groups
  3. 15.3ElePHPants
  4. 15.4Interacting with Databases
  5. 15.5MySQL Extension
  6. 15.6PDO Extension
  7. 15.7Abstraction Layers

16.Databases

  1. 16.1PHPDoc

17.Documenting your Code

Causes

Causes Supported

Protect Earth

Protect Earth

https://protect.earth
We plant trees, wildflowers, and remove invasives to tackle the climate/biodiversity crises, and literally everyone can get involved! Registered charity 1192453
Protect Earth create, restores, and protects woodlands all over the UK. We plant tens of thousands of trees every year on low quality farmland, schools, wedding venues, council land, road verges, golf courses, or anywhere else that makes sense. Increasingly Protect Earth is securing its own land, restoring an ancient temporate rainforest in Cornwall, and creating a brand new temperate rainforest in Wales.
Electronic Frontier Foundation

Electronic Frontier Foundation

Defending your civil liberties in a digital world.

https://www.eff.org/
Based in San Francisco, EFF is a donor-supported membership organization working to protect fundamental rights regardless of technology.
From the Internet to the iPod, technologies are transforming our society and empowering us as speakers, citizens, creators, and consumers. When our freedoms in the networked world come under attack, the Electronic Frontier Foundation (EFF) is the first line of defense. EFF broke new ground when it was founded in 1990—well before the Internet was on most people's radar—and continues to confront cutting-edge issues defending free speech, privacy, innovation, and consumer rights today. From the beginning, EFF has championed the public interest in every critical battle affecting digital rights.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub