About the Author |
|
xix | |
About the Technical Reviewer |
|
xxi | |
Acknowledgments |
|
xxiii | |
Introduction |
|
xxv | |
Part I: Objects |
|
1 | (238) |
|
Chapter 1 PHP: Design and Management |
|
|
3 | (10) |
|
|
3 | (2) |
|
|
5 | (3) |
|
|
8 | (3) |
|
|
8 | (1) |
|
|
9 | (1) |
|
|
9 | (2) |
|
What's New in the Sixth Edition |
|
|
11 | (1) |
|
|
11 | (2) |
|
Chapter 2 PHP and Objects |
|
|
13 | (8) |
|
The Accidental Success of PHP Objects |
|
|
13 | (6) |
|
|
13 | (1) |
|
|
14 | (1) |
|
PHP 4 and the Quiet Revolution |
|
|
14 | (3) |
|
|
17 | (1) |
|
|
18 | (1) |
|
PHP 8: The Consolidation Continues |
|
|
19 | (1) |
|
Advocacy and Agnosticism: The Object Debate |
|
|
19 | (1) |
|
|
20 | (1) |
|
|
21 | (58) |
|
|
21 | (3) |
|
|
21 | (1) |
|
|
22 | (2) |
|
Setting Properties in a Class |
|
|
24 | (3) |
|
|
27 | (2) |
|
Creating a Constructor Method |
|
|
29 | (4) |
|
Constructor Property Promotion |
|
|
31 | (2) |
|
Default Arguments and Named Arguments |
|
|
33 | (1) |
|
|
34 | (16) |
|
|
35 | (4) |
|
Some Other Type-Checking Functions |
|
|
39 | (1) |
|
Type Declarations: Object Types |
|
|
40 | (3) |
|
Type Declarations: Primitive Types |
|
|
43 | (2) |
|
|
45 | (2) |
|
|
47 | (3) |
|
|
50 | (1) |
|
|
50 | (1) |
|
|
51 | (26) |
|
|
52 | (7) |
|
|
59 | (8) |
|
Public, Private, and Protected: Managing Access to Your Classes |
|
|
67 | (4) |
|
|
71 | (6) |
|
|
77 | (2) |
|
Chapter 4 Advanced Features |
|
|
79 | (74) |
|
Static Methods and Properties |
|
|
79 | (6) |
|
|
85 | (1) |
|
|
86 | (3) |
|
|
89 | (3) |
|
|
92 | (13) |
|
A Problem for Traits to Solve |
|
|
93 | (1) |
|
Defining and Using a Trait |
|
|
94 | (1) |
|
Using More Than One Trait |
|
|
95 | (2) |
|
Combining Traits and Interfaces |
|
|
97 | (1) |
|
Managing Method Name Conflicts with insteadof |
|
|
98 | (1) |
|
Aliasing Overridden Trait Methods |
|
|
99 | (1) |
|
Using Static Methods in Traits |
|
|
100 | (1) |
|
Accessing Host Class Properties |
|
|
101 | (1) |
|
Defining Abstract Methods in Traits |
|
|
102 | (2) |
|
Changing Access Rights to Trait Methods |
|
|
104 | (1) |
|
Late Static Bindings: The static Keyword |
|
|
105 | (4) |
|
|
109 | (13) |
|
|
112 | (10) |
|
Final Classes and Methods |
|
|
122 | (2) |
|
|
124 | (1) |
|
Working with Interceptors |
|
|
125 | (9) |
|
Defining Destructor Methods |
|
|
134 | (2) |
|
Copying Objects with _clone() |
|
|
136 | (4) |
|
Defining String Values for Your Objects |
|
|
140 | (2) |
|
Callbacks, Anonymous Functions, and Closures |
|
|
142 | (8) |
|
|
150 | (2) |
|
|
152 | (1) |
|
|
153 | (56) |
|
|
153 | (19) |
|
PHP Packages and Namespaces |
|
|
154 | (13) |
|
|
167 | (5) |
|
The Class and Object Functions |
|
|
172 | (13) |
|
|
174 | (1) |
|
Learning About an Object or Class |
|
|
175 | (2) |
|
Getting a Fully Qualified String Reference to a Class |
|
|
177 | (1) |
|
|
178 | (3) |
|
Learning About Properties |
|
|
181 | (1) |
|
Learning About Inheritance |
|
|
181 | (1) |
|
|
182 | (3) |
|
|
185 | (17) |
|
|
185 | (1) |
|
Time to Roll Up Your Sleeves |
|
|
186 | (3) |
|
|
189 | (2) |
|
|
191 | (3) |
|
Examining Method Arguments |
|
|
194 | (3) |
|
|
197 | (5) |
|
|
202 | (6) |
|
|
208 | (1) |
|
Chapter 6 Objects and Design |
|
|
209 | (30) |
|
|
209 | (1) |
|
Object-Oriented and Procedural Programming |
|
|
210 | (8) |
|
|
216 | (1) |
|
|
217 | (1) |
|
|
217 | (1) |
|
|
217 | (1) |
|
|
218 | (1) |
|
|
219 | (2) |
|
|
221 | (2) |
|
|
223 | (1) |
|
|
224 | (1) |
|
|
224 | (1) |
|
The Class Who Knew Too Much |
|
|
224 | (1) |
|
|
225 | (1) |
|
|
225 | (1) |
|
|
225 | (13) |
|
|
226 | (9) |
|
|
235 | (3) |
|
|
238 | (1) |
Part II: Patterns |
|
239 | (318) |
|
Chapter 7 What Are Design Patterns? Why Use Them? |
|
|
241 | (12) |
|
What Are Design Patterns? |
|
|
241 | (3) |
|
A Design Pattern Overview |
|
|
244 | (2) |
|
|
244 | (1) |
|
|
245 | (1) |
|
|
245 | (1) |
|
|
246 | (1) |
|
|
246 | (1) |
|
|
247 | (3) |
|
A Design Pattern Defines a Problem |
|
|
247 | (1) |
|
A Design Pattern Defines a Solution |
|
|
248 | (1) |
|
Design Patterns Are Language Independent |
|
|
248 | (1) |
|
Patterns Define a Vocabulary |
|
|
248 | (1) |
|
Patterns Are Tried and Tested |
|
|
249 | (1) |
|
Patterns Are Designed for Collaboration |
|
|
249 | (1) |
|
Design Patterns Promote Good Design |
|
|
250 | (1) |
|
Design Patterns Are Used by Popular Frameworks |
|
|
250 | (1) |
|
|
250 | (1) |
|
|
251 | (2) |
|
Chapter 8 Some Pattern Principles |
|
|
253 | (20) |
|
|
253 | (1) |
|
Composition and Inheritance |
|
|
254 | (8) |
|
|
254 | (4) |
|
|
258 | (4) |
|
|
262 | (5) |
|
|
262 | (2) |
|
|
264 | (3) |
|
Code to an Interface, Not to an Implementation |
|
|
267 | (2) |
|
|
269 | (1) |
|
|
270 | (1) |
|
|
270 | (1) |
|
Patterns for Generating Objects |
|
|
271 | (1) |
|
Patterns for Organizing Objects and Classes |
|
|
271 | (1) |
|
|
271 | (1) |
|
|
271 | (1) |
|
|
271 | (1) |
|
|
271 | (2) |
|
Chapter 9 Generating Objects |
|
|
273 | (58) |
|
Problems and Solutions in Generating Objects |
|
|
273 | (7) |
|
|
280 | (5) |
|
|
280 | (1) |
|
|
281 | (3) |
|
|
284 | (1) |
|
|
285 | (8) |
|
|
285 | (4) |
|
|
289 | (3) |
|
|
292 | (1) |
|
|
293 | (7) |
|
|
293 | (2) |
|
|
295 | (3) |
|
|
298 | (2) |
|
|
300 | (7) |
|
|
301 | (1) |
|
|
302 | (5) |
|
Pushing to the Edge: Service Locator |
|
|
307 | (2) |
|
Splendid Isolation: Dependency Injection |
|
|
309 | (21) |
|
|
309 | (1) |
|
|
310 | (18) |
|
|
328 | (2) |
|
|
330 | (1) |
|
Chapter 10 Patterns for Flexible Object Programming |
|
|
331 | (32) |
|
Structuring Classes to Allow Flexible Objects |
|
|
331 | (1) |
|
|
332 | (15) |
|
|
332 | (4) |
|
|
336 | (6) |
|
|
342 | (5) |
|
|
347 | (1) |
|
|
347 | (10) |
|
|
347 | (3) |
|
|
350 | (6) |
|
|
356 | (1) |
|
|
357 | (5) |
|
|
357 | (3) |
|
|
360 | (1) |
|
|
361 | (1) |
|
|
362 | (1) |
|
Chapter 11 Performing and Representing Tasks |
|
|
363 | (58) |
|
|
363 | (14) |
|
|
364 | (1) |
|
|
365 | (12) |
|
|
377 | (1) |
|
|
377 | (6) |
|
|
377 | (2) |
|
|
379 | (4) |
|
|
383 | (12) |
|
|
387 | (8) |
|
|
395 | (10) |
|
|
395 | (3) |
|
|
398 | (7) |
|
|
405 | (1) |
|
|
405 | (8) |
|
|
406 | (1) |
|
|
406 | (7) |
|
|
413 | (6) |
|
|
414 | (3) |
|
|
417 | (2) |
|
|
419 | (2) |
|
Chapter 12 Enterprise Patterns |
|
|
421 | (70) |
|
|
422 | (4) |
|
|
422 | (1) |
|
|
423 | (3) |
|
|
426 | (8) |
|
|
426 | (2) |
|
|
428 | (6) |
|
|
434 | (45) |
|
|
435 | (15) |
|
|
450 | (18) |
|
|
468 | (7) |
|
Template View and View Helper |
|
|
475 | (4) |
|
|
479 | (11) |
|
|
479 | (6) |
|
|
485 | (5) |
|
|
490 | (1) |
|
Chapter 13 Database Patterns |
|
|
491 | (66) |
|
|
491 | (1) |
|
|
492 | (22) |
|
|
492 | (1) |
|
|
493 | (20) |
|
|
513 | (1) |
|
|
514 | (6) |
|
|
514 | (2) |
|
|
516 | (4) |
|
|
520 | (1) |
|
|
520 | (12) |
|
|
521 | (1) |
|
|
521 | (7) |
|
|
528 | (1) |
|
|
528 | (1) |
|
|
528 | (1) |
|
|
529 | (2) |
|
|
531 | (1) |
|
|
532 | (4) |
|
|
532 | (1) |
|
|
532 | (2) |
|
|
534 | (2) |
|
|
536 | (9) |
|
|
536 | (1) |
|
|
537 | (8) |
|
|
545 | (1) |
|
The Selection Factory and Update Factory Patterns |
|
|
545 | (7) |
|
|
545 | (1) |
|
|
546 | (5) |
|
|
551 | (1) |
|
What's Left of Data Mapper Now? |
|
|
552 | (3) |
|
|
555 | (2) |
Part III: Practice |
|
557 | (224) |
|
Chapter 14 Good (and Bad) Practice |
|
|
559 | (12) |
|
|
560 | (1) |
|
|
560 | (3) |
|
|
563 | (1) |
|
|
564 | (1) |
|
|
565 | (1) |
|
|
566 | (1) |
|
|
567 | (1) |
|
|
568 | (1) |
|
|
569 | (2) |
|
|
571 | (24) |
|
|
571 | (1) |
|
What Are PHP Standards Recommendations? |
|
|
572 | (3) |
|
|
573 | (1) |
|
|
574 | (1) |
|
|
575 | (14) |
|
PSR-1 Basic Coding Standard |
|
|
575 | (4) |
|
PSR-12 Extended Coding Style |
|
|
579 | (7) |
|
Checking and Fixing Your Code |
|
|
586 | (3) |
|
|
589 | (4) |
|
The Rules That Matter to Us |
|
|
589 | (4) |
|
|
593 | (2) |
|
Chapter 16 PHP Using and Creating Components with Composer |
|
|
595 | (18) |
|
|
596 | (1) |
|
|
596 | (1) |
|
Installing a (Set of) Package(s) |
|
|
596 | (6) |
|
Installing a Package from the Command Line |
|
|
598 | (1) |
|
|
598 | (2) |
|
|
600 | (2) |
|
|
602 | (1) |
|
Creating Your Own Package |
|
|
603 | (2) |
|
Adding Package Information |
|
|
603 | (1) |
|
|
604 | (1) |
|
Distribution Through Packagist |
|
|
605 | (4) |
|
|
609 | (2) |
|
|
611 | (2) |
|
Chapter 17 Version Control with Git |
|
|
613 | (32) |
|
|
613 | (2) |
|
|
615 | (1) |
|
Using an Online Git Repository |
|
|
616 | (2) |
|
|
618 | (3) |
|
Creating the Remote Repository |
|
|
619 | (2) |
|
|
621 | (5) |
|
|
625 | (1) |
|
|
626 | (4) |
|
Adding and Removing Files and Directories |
|
|
630 | (3) |
|
|
631 | (1) |
|
|
631 | (1) |
|
|
632 | (1) |
|
|
633 | (1) |
|
|
633 | (1) |
|
|
634 | (10) |
|
|
644 | (1) |
|
Chapter 18 Testing with PHPUnit |
|
|
645 | (42) |
|
Functional Tests and Unit Tests |
|
|
646 | (1) |
|
|
646 | (4) |
|
|
650 | (20) |
|
|
651 | (3) |
|
|
654 | (1) |
|
|
655 | (1) |
|
|
656 | (1) |
|
|
657 | (3) |
|
|
660 | (4) |
|
Tests Succeed When They Fail |
|
|
664 | (6) |
|
|
670 | (14) |
|
Refactoring a Web Application for Testing |
|
|
670 | (3) |
|
|
673 | (3) |
|
|
676 | (8) |
|
|
684 | (2) |
|
|
686 | (1) |
|
Chapter 19 Automated Build with Phing |
|
|
687 | (32) |
|
|
688 | (1) |
|
Getting and Installing Phing |
|
|
689 | (1) |
|
Composing the Build Document |
|
|
689 | (28) |
|
|
692 | (3) |
|
|
695 | (9) |
|
|
704 | (7) |
|
|
711 | (6) |
|
|
717 | (2) |
|
|
719 | (14) |
|
|
719 | (1) |
|
|
720 | (3) |
|
Choosing and Installing a Vagrant Box |
|
|
721 | (2) |
|
Mounting Local Directories on the Vagrant Box |
|
|
723 | (2) |
|
|
725 | (6) |
|
Setting Up the Web Server |
|
|
727 | (1) |
|
|
728 | (1) |
|
|
729 | (2) |
|
|
731 | (1) |
|
|
732 | (1) |
|
Chapter 21 Continuous Integration |
|
|
733 | (32) |
|
What Is Continuous Integration? |
|
|
733 | (30) |
|
Preparing a Project for CI |
|
|
735 | (14) |
|
Installing Jenkins Plug-ins |
|
|
749 | (1) |
|
Setting Up the Git Public Key |
|
|
750 | (1) |
|
|
751 | (5) |
|
|
756 | (1) |
|
|
757 | (3) |
|
|
760 | (3) |
|
|
763 | (2) |
|
Chapter 22 Objects, Patterns, Practice |
|
|
765 | (16) |
|
|
765 | (4) |
|
|
766 | (1) |
|
Encapsulation and Delegation |
|
|
766 | (1) |
|
|
767 | (1) |
|
|
768 | (1) |
|
|
768 | (1) |
|
|
769 | (4) |
|
|
770 | (1) |
|
Patterns and Principles of Design |
|
|
771 | (2) |
|
|
773 | (5) |
|
|
774 | (1) |
|
|
774 | (1) |
|
|
775 | (1) |
|
|
775 | (1) |
|
|
776 | (1) |
|
|
776 | (2) |
|
|
778 | (3) |
Appendix A: Bibliography |
|
781 | (4) |
|
|
781 | (1) |
|
|
782 | (1) |
|
|
782 | (3) |
Appendix B: A Simple Parser |
|
785 | (32) |
|
|
785 | (12) |
|
|
797 | (20) |
Index |
|
817 | |