Home / Good Books To Read / Book Reviews – Modern PHP New Features and Good Practices

Book Reviews – Modern PHP New Features and Good Practices

Book Reviews - Modern PHP New Features and Good Practices

PHP is experiencing a renaissance, though it may be difficult to tell with all of the outdated PHP tutorials online. With this practical guide, you’ll learn how PHP has become a full-featured, mature language with object-orientation, namespaces, and a growing collection of reusable component libraries.

Author Josh Lockhart creator of PHP The Right Way, a popular initiative to encourage PHP best practices reveals these new language features in action. You’ll learn best practices for application architecture and planning, databases, security, testing, debugging, and deployment. If you have a basic understanding of PHP and want to bolster your skills, this is your book.

Learn modern PHP features, such as namespaces, traits, generators, and closures
Discover how to find, use, and create PHP components
Follow best practices for application security, working with databases, errors and exceptions, and more
Learn tools and techniques for deploying, tuning, testing, and profiling your PHP applications
Explore Facebook’s HVVM and Hack language implementations and how they affect modern PHP
Build a local development environment that closely matches your production server

Part I. Language Features
1. The New PHP
Past 1
Present 2
Future 3
2. Features
Namespaces 5
Why We Use Namespaces 7
Declaration 8
Import and Alias 9
Helpful Tips 11
Code to an Interface 13
Traits 17
Why We Use Traits 18
How to Create a Trait 19
How to Use a Trait 20
Generators 22
Create a Generator 22
Use a Generator 23
Closures 25
Create 25
Attach State 27
Zend OPcache 29
Enable Zend OPcache 29
Configure Zend OPcache 31
Use Zend OPcache 31
Built-in HTTP server 31
Start the Server 32
Configure the Server 32
Router Scripts 33
Detect the Built-in Server 33
Drawbacks 33
What’s Next 34
Part II. Good Practices
3. Standards
PHP-FIG to the Rescue 37
Framework Interoperability 38
Interfaces 38
Autoloading 39
Style 39
What Is a PSR? 40
PSR-1: Basic Code Style 40
PSR-2: Strict Code Style 41
PSR-3: Logger Interface 45
Write a PSR-3 Logger 46
Use a PSR-3 Logger 47
PSR-4: Autoloaders 47
Why Autoloaders Are Important 47
The PSR-4 Autoloader Strategy 48
How to Write a PSR-4 Autoloader (and Why You Shouldn’t) 49
4. Components
Why Use Components? 51
What Are Components? 52
Components Versus Frameworks 53
Not All Frameworks Are Bad 54
Use the Right Tool for the Job 54
Find Components 55
Shop 56
Choose 56
Leave Feedback 57
Use PHP Components 57
How to Install Composer 58
How to Use Composer 59
Example Project 61
Composer and Private Repositories 64
Create PHP Components 66
Vendor and Package Names 66
Namespaces 66
Filesystem Organization 67
The composer.json File 68
The README file 70
Component Implementation 71
Version Control 72
Packagist Submission 73
Using the Component 74
5. Good Practices
Sanitize, Validate, and Escape 75
Sanitize Input 76
Validate Data 79
Escape Output 80
Passwords 80
Never Know User Passwords 81
Never Restrict User Passwords 81
Never Email User Passwords 81
Hash User Passwords with bcrypt 82
Password Hashing API 82
Password Hashing API for PHP < 5.5.0 87
Dates, Times, and Time Zones 87
Set a Default Time Zone 88
The DateTime Class 88
The DateInterval Class 89
The DateTimeZone Class 91
The DatePeriod Class 92
The nesbot/carbon Component 93
Databases 93
The PDO Extension 93
Database Connections and DSNs 93
Prepared Statements 96
Query Results 98
Transactions 100
Multibyte Strings 103
Character Encoding 104
Output UTF-8 Data 105
Streams 106
Stream Wrappers 106
Stream Context 109
Stream Filters 110
Custom Stream Filters 112
Errors and Exceptions 115
Exceptions 115
Exception Handlers 118
Errors 119
Error Handlers 121
Errors and Exceptions During Development 123
Production 124
Part III. Deployment, Testing, and Tuning
6. Hosting
Shared Server 129
Virtual Private Server 130
Dedicated Server 131
PaaS 131
Choose a Hosting Plan 132
7. Provisioning
Our Goal 134
Server Setup 134
First Login 134
Software Updates 135
Nonroot User 135
SSH Key-Pair Authentication 136
Disable Passwords and Root Login 138
PHP-FPM 138
Install 138
Global Configuration 139
Pool Configuration 140
nginx 143
Install 143
Virtual Host 143
Automate Server Provisioning 146
Delegate Server Provisioning 146
Further Reading 147
What’s Next 147
8. Tuning
The php.ini File 149
Memory 150
Zend OPcache 151
File Uploads 152
Max Execution Time 153
Session Handling 154
Output Buffering 155
Realpath Cache 155
Up Next 155
9. Deployment
Version Control 157
Automate Deployment 157
Make It Simple 158
Make It Predictable 158
Make It Reversible 158
Capistrano 158
How It Works 158
Install 159
Configure 159
Authenticate 161
Prepare the Remote Server 161
Capistrano Hooks 162
Deploy Your Application 163
Roll Back Your Application 163
Further Reading 163
What’s Next 163
10. Testing
Why Do We Test? 165
When Do We Test? 166
Before 166
During 166
After 166
What Do We Test? 166
How Do We Test? 167
Unit Tests 167
Test-Driven Development (TDD) 167
Behavior-Driven Development (BDD) 167
PHPUnit 168
Directory Structure 169
Install PHPUnit 170
Install Xdebug 170
Configure PHPUnit 171
The Whovian Class 172
The WhovianTest Test Case 173
Run Tests 175
Code Coverage 176
Continuous Testing with Travis CI 177
Setup 177
Run 178
Further Reading 178
What’s Next 179
11. Profiling
When to Use a Profiler 181
Types of Profilers 181
Xdebug 182
Configure 182
Trigger 183
Analyze 183
XHProf 183
Install 184
XHGUI 184
Configure 185
Trigger 185
New Relic Profiler 185
Blackfire Profiler 186
Further Reading 186
What’s Next 186
12. HHVM and Hack
HHVM 187
PHP at Facebook 188
HHVM and Zend Engine Parity 189
Is HHVM Right for Me? 190
Install 190
Configure 191
Extensions 192
Monitor HHVM with Supervisord 192
HHVM, FastCGI, and Nginx 194
The Hack Language 195
Convert PHP to Hack 196
What is a Type? 196
Static Typing 197
Dynamic Typing 198
Hack Goes Both Ways 198
Hack Type Checking 199
Hack Modes 200
Hack Syntax 200
Hack Data Structures 202
HHVM/Hack vs. PHP 203
Further Reading 204
13. Community
Local PUG 205
Conferences 205
Mentoring 206
Stay Up-to-Date 206
Websites 206
Mailing Lists 206
Twitter 206
Podcasts 206
Humor 207
A. Install PHP
B. Local Development Environments

Book Reviews – Modern PHP New Features and Good Practices


Top books

About huydam

Check Also

[Javascript] How to sum of all its digits for a number

Given a number x, find sum of digits in that number. Examples: 1. Input n …

Leave a Reply

Your email address will not be published. Required fields are marked *