From Fundamentals to Expert-Level Programming with PHP 8
Introduction: The PHP You Don’t Know Yet
- Why This Book?
- How This Book Is Structured
- What You Need to Get Started
- How to Read This Book
- A Note on PHP Versions
Chapter 1: Getting Started with PHP
- What Is PHP?
- Installing and Configuring PHP
- Your First PHP Program
- How PHP Executes Code
- Development Tools and IDEs
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 2: Variables, Data Types, and Constants
- Variables and Naming Conventions
- Scalar Types
- Compound Types
- Special Types
- Constants and Typed Constants
- Type Juggling and Strict Types
- Deep Dive: How PHP Stores Values Internally
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 3: Operators and Expressions
- Arithmetic and Assignment Operators
- Comparison Operators
- Logical and Bitwise Operators
- Null Coalescing and Elvis Operators
- String Concatenation and Interpolation
- Operator Precedence and Associativity
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 4: Control Flow
- If, Elseif, and Else Statements
- Switch Statements
- The Match Expression (PHP 8.0+)
- For, Foreach, While, and Do-While Loops
- Break, Continue, and Goto
- Error Control Operator (@)
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 5: Functions Deep Dive
- Defining and Calling Functions
- Parameters, Arguments, and Default Values
- Named Arguments (PHP 8.0+)
- Variable-Length Arguments (…args)
- Return Types and Union Types
- Anonymous Functions and Closures
- Arrow Functions (PHP 7.4+)
- First-Class Callable Syntax (PHP 8.1+)
- Recursion and Callbacks
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 6: Arrays–PHP’s Workhorse
- Indexed and Associative Arrays
- Multidimensional Arrays
- Array Functions (Map, Filter, Reduce Patterns)
- Array Destructuring (PHP 7.1+)
- SplFixedArray and Specialized Arrays
- Performance Considerations with Large Arrays
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 7: Strings and Text Processing
- String Literals (Single vs Double Quotes)
- String Functions and Manipulation
- String Interpolation and Heredoc/Nowdoc
- Regular Expressions with PCRE
- Multibyte String Handling (mbstring)
- String Comparison and Collation
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 8: Object-Oriented Programming Foundations
- Classes and Objects
- Properties and Visibility
- Methods and the
$thisKeyword - Constructors and Destructors
- Static Properties and Methods
- Magic Methods
- Late Static Binding
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 9: Advanced Object-Oriented Features
- Inheritance and Method Overriding
- Abstract Classes and Methods
- Interfaces and Multiple Interface Implementation
- Traits and Trait Conflicts
- Readonly Properties and Classes (PHP 8.1+)
- Enums (PHP 8.1+)
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 10: Namespaces, Autoloading, and Attributes
- Namespaces and Aliasing
- PSR-4 Autoloading Standard
- Composer and Dependency Management
- Attributes (PHP 8.0+)
- Reflection API
- The Standard PHP Library (SPL)
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 11: Error Handling and Exceptions
- Errors vs Exceptions in PHP
- Try, Catch, Finally Blocks
- Custom Exception Classes
- The Throwable Interface Hierarchy
- Error Handling Functions and Callbacks
- The Nullsafe Operator (PHP 8.0+)
- Debugging Techniques
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 12: Generators, Iterators, and Fibers
- Generators (yield)
- Generator Delegation (yield from)
- Generator Send and Return Values
- Iterator Interface and SPL Iterators
- The Iterable Pseudo-Type
- Fibers (PHP 8.1+)
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 13: File I/O, Streams, and Serialization
- File Reading and Writing
- Directory Operations
- Stream Wrappers and Filters
- JSON Encoding and Decoding
- Serialization and Unserialization
- CSV Processing
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 14: Type System Mastery
- Scalar Type Declarations
- Return Type Declarations
- Union Types (PHP 8.0+)
- Intersection Types (PHP 8.1+)
- The Standalone Null and False Types (PHP 8.2+)
- The True Type (PHP 8.2+)
- Typed Class Constants (PHP 8.3+)
- Type System Deep Dive: How PHP Checks Types
- Chapter Summary
- Review Questions
- Hands-On Exercise
Chapter 15: Performance, Security, and Professional Practices
- Memory Management and Garbage Collection
- Performance Optimization Techniques
- Security Best Practices at the Language Level
- Coding Standards (PSR-12)
- Static Analysis with PHPStan and Psalm
- Testing Fundamentals (PHPUnit basics)
- Modern Development Workflow
- Chapter Summary
- Review Questions
- Hands-On Exercise
Conclusion: The Future of PHP
- Where to Go From Here
- The Bigger Picture
- Final Thoughts