The Art of Modern PHP 8: Learn how to write modern, performant, and enterprise-ready code with the latest PHP features and practices

The Art of Modern PHP 8: Learn how to write modern, performant, and enterprise-ready code with the latest PHP features and practices

The Art of Modern PHP 8: Learn how to write modern, performant, and enterprise-ready code with the latest PHP features and practices
Автор: Edmonds Joseph
Дата выхода: 2021
Издательство: Packt Publishing Limited
Количество страниц: 421
Размер файла: 2.8 MB
Тип файла: PDF
Добавил: codelibs
 Проверить на вирусы

Cover....1

Title....2

Copyright and Credits....2

Foreword....4

Table of Contents....10

Section 1 – PHP 8 OOP....22

Chapter 1: Object-Oriented PHP....24

What is OOP?....25

Understanding the phrase....25

OOP alternatives....28

Learning object-oriented PHP....31

PHP OOP basics....36

Classes....36

Interfaces....41

Namespaces....42

Summary....44

Chapter 2: Inheritance and Composition, Encapsulation and Visibility, Interfaces and Concretions....46

Encapsulation and visibility....47

Private, protected, and public....48

Inheritance–the classical parent, child, and "is a" style....49

Constructor promotion....63

Composition–the modern, flexible "has a" style....70

Interfaces instead of abstract classes....81

Summary....82

Chapter 3: Advanced OOP Features....84

SPL – the Standard PHP Library....85

Data structures....85

Iterators....86

Exceptions and error handling....100

Yoda and Pokemon exception handling....107

Exception and error handling best practices....108

Meta-programming with reflection and attributes....112

Reflection....112

Attributes....115

Summary....120

Section 2 – PHP Types....122

Chapter 4: Scalar, Arrays, and Special Types....124

Scalar types....126

Strings....126

Ints....134

Floats....135

Bools....138

Type juggling....139

Type and value comparison....139

Arrays and iterables....145

Arrays....145

Iterables....149

DocBlock types....152

Nullable, void, and uninitialised....154

Null and nullable....154

Void....157

Uninitialised....159

Resources....160

Summary....162

Chapter 5: Object Types, Interfaces, and Unions....164

Object type inheritance....165

Object comparison....174

Passing objects by reference....177

Making new objects....179

Summary....188

Chapter 6: Parameter, Property, and Return Types....190

Coercive and strict modes....191

Covariance and contravariance....203

Contravariance – that is, allowing less specific parameter types than the parent....204

Covariance – that is, allowing more specific return types than the parent....204

Remembering the rules....210

Summary....210

Section 3 – Clean PHP 8 Patterns and Style....212

Chapter 7: Design Patterns and Clean Code....214

Clean Code Acronyms (CCA)....216

DRY....223

KICK....224

Design patterns....239

Creational patterns....239

Structural patterns....242

Behavioral patterns....247

Architectural patterns....249

Summary....250

Chapter 8: Model, View, Controller (MVC) Example....252

Model, View, Controller – MVC....253

Controller....253

Front controller....254

Model....268

Entity pattern....268

Universally unique identifier (UUID)....270

Persistence and ORM....273

Singleton anti-pattern....274

Repository pattern....274

Collection pattern....276

View....279

It lives....286

Summary....292

Chapter 9: Dependency Injection Example....294

Inversion of control container....295

Dependency injection and the service locator....295

The service locator anti-pattern....316

Summary....317

Chapter 10: Composer For Dependencies....322

What is Composer?....323

What are dependencies?....323

Dependency resolution....324

But wait, there's more....325

In a nutshell, it's awesome....325

Get it installed!....326

Composer autoloader....326

Old-fashioned versus autoloaded....326

A real-world, old-fashioned example....329

Extra points....330

Autoloading in PHP....330

Configuring Composer autoloader....333

Using Composer to require packages....334

Finding dependencies....334

Initialisation of composer.json....335

What is a vendor?....336

Minimum stability....336

Package type....336

License....337

So far, so good....337

Installing monolog....338

Ignore the vendor directory in your VCS....341

The composer.lock file....341

Adding extra dependencies....342

Version constraints....344

Semver in a nutshell....344

Caret (^) Version Range....345

Tilde (~) Version Range....345

Exact version....346

Version range....346

Multiple acceptable versions....346

Full documentation....347

Dev and prod dependencies....347

Requiring dev dependencies....347

Installing without dev dependencies....348

Summary....348

Chapter 11: Creating Your Own Composer Package....350

Writing composer.json....351

Name....353

Description....353

Keywords....353

License....353

Using source folders and namespaces....354

Executable Binaries Configured under bin....356

Extensionless files....358

Executable permissions....358

Finding an autoloader....358

Using versions and tagging....358

Creating a Git tag....359

SemVer....360

Stable and development versions....361

Private Git repos as Composer dependencies....362

Publishing on Packagist....363

Things to check before you publish....363

Submitting your package to Packagist....364

Created....365

If you were just testing, delete it....366

Summary....367

Section 5 – Bonus Section - PHP 8.1....368

Chapter 12: The Awesomeness That Is 8.1....370

Enumerations....371

Basic and backed enums....371

Creating enum instances....374

Not just classes with cases....376

Readonly properties....377

Readonly gotchas....386

Intersection types....392

Never return type....398

Final constants....400

Summary – end of the book....405

Other Books You May Enjoy....409

Index....412

As PHP has such a long history, it also means that there are many developers out there who are still standing with at least one foot in the past and are missing out on the bright and beautiful future of modern PHP. This book is for you, most of all.The book is for existing PHP developers and CTO-level professionals who are working with PHP technologies, including legacy PHP, in production. The book assumes a reasonable level of knowledge of PHP programming and may require you to hit the PHP documentation to fill in gaps in your knowledge as they come up.


Похожее:

Список отзывов:

Нет отзывов к книге.