Discover how stronger types mean cleaner code and better running and optimized PHP applications. This unique book looks at typed PHP: PHP types, strings, regular expressions, and more from PHP 7 as found in standard PHP libraries, user libraries, extensions, and cross-compilers. You'll see how to create a set of reusable tools that unify and ease the scalar types of PHP. This is an important topic for creating in your web development and other projects.
PHP has a rich history and a dominant place on the web. It has achieved much despite language inconsistencies and difficulties. Bjarne Stroustrup once said: "There are only two kinds of languages: the ones people complain about and the ones nobody uses".
PHP is one of those languages that everybody uses, yet that's often seen as a good reason to ignore the bad parts and just get stuff done. We're all for getting stuff done, and to that end, the author has used Plain Ol' PHP for many years. It's always bugged him how procedural PHP is, in an ecosystem of OOP libraries and frameworks. So he decided to take a deeper look at building a stronger type system on top of PHP. That's the goal of this book.
What you'll learn
- Discover the fundamentals of PHP strings, regex, underscores, native function inconsistencies, and more
- Examine the structure of PHP types including boxing, regex, namespace functions, composer autoload, null problem, optional values, and more
- Work with extensions like vagrant + phansible, provisioning, vagrant commands, SPL types, scalar objects, zephir, and more
- Design using scalar, SPL, zephir, structure types, resolving types, chaining, combining number types, PHPUnit, packaging, and more
- Plan for the future using a case study example
Who is this book for
This book is for experienced web developers and PHP programmers.
About the Author |
|
xi | |
About the Technical Reviewer |
|
xiii | |
Acknowledgments |
|
xv | |
Introduction |
|
xvii | |
|
Chapter 1 The State of PHP |
|
|
1 | (6) |
|
Procedural versus Object Oriented |
|
|
1 | (2) |
|
|
1 | (1) |
|
Object Oriented Programming |
|
|
2 | (1) |
|
|
3 | (1) |
|
|
3 | (1) |
|
Native Function Inconsistencies |
|
|
3 | (3) |
|
|
4 | (1) |
|
|
4 | (1) |
|
Inconsistent Argument Order |
|
|
5 | (1) |
|
Regular Expression/Strings |
|
|
5 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
6 | (1) |
|
|
7 | (12) |
|
|
7 | (2) |
|
|
9 | (4) |
|
|
10 | (1) |
|
|
11 | (2) |
|
|
13 | (1) |
|
|
13 | (2) |
|
|
14 | (1) |
|
Importing Namespaced Functions |
|
|
14 | (1) |
|
|
15 | (3) |
|
|
15 | (1) |
|
|
16 | (1) |
|
|
17 | (1) |
|
|
18 | (1) |
|
|
19 | (14) |
|
|
19 | (6) |
|
|
19 | (3) |
|
|
22 | (2) |
|
|
24 | (1) |
|
|
25 | (2) |
|
|
25 | (1) |
|
|
26 | (1) |
|
|
27 | (3) |
|
Installing Scalar Objects |
|
|
28 | (1) |
|
|
29 | (1) |
|
|
30 | (2) |
|
|
30 | (1) |
|
|
30 | (2) |
|
|
32 | (1) |
|
|
33 | (18) |
|
|
33 | (1) |
|
|
33 | (1) |
|
|
34 | (1) |
|
|
34 | (1) |
|
|
34 | (9) |
|
|
35 | (2) |
|
|
37 | (2) |
|
|
39 | (4) |
|
|
43 | (2) |
|
|
43 | (1) |
|
|
44 | (1) |
|
How to Structure Functions |
|
|
45 | (2) |
|
|
45 | (1) |
|
|
46 | (1) |
|
|
47 | (1) |
|
|
47 | (1) |
|
|
47 | (1) |
|
|
48 | (1) |
|
When Should We Write Tests? |
|
|
48 | (1) |
|
|
48 | (1) |
|
|
48 | (1) |
|
|
48 | (1) |
|
Installation Instructions |
|
|
49 | (1) |
|
|
49 | (1) |
|
|
49 | (1) |
|
|
49 | (2) |
|
|
51 | (24) |
|
|
51 | (14) |
|
|
51 | (7) |
|
|
58 | (7) |
|
|
65 | (9) |
|
|
65 | (9) |
|
|
74 | (1) |
Index |
|
75 | |
Christopher Pitt is an expert web developer, PHP programmer/coder and writer, working at SilverStripe. He usually works on application architecture, though sometimes you'll find him building compilers or robots.