Core OOP Coding Differences
There are two words that causes any developer to start looking nervously over his or her shoulder: _backwards incompatible_. Thus was born the phrase _BC Breaks_ meaning code that breaks due to backwards compatibility issues. In this unit we cover core PHP 8 language coding differences you must learn about in order avoid BC breaks.
This unit includes the following topics:
- Core OOP Coding Differences
- Magic Method Changes: Constructor
- Magic Method Signatures
- Magic Method Signatures Example
- Magic Method Changes: Sleep
- Serialization Differences
- Custom Serialization
- Custom Serialization Example
- Private Method Signatures
- Private Method Signature Example
- Static Anyone?
- Object Properties No Longer Array Keys
- Anonymous Class Control
- Stringable Interface
- Namespace Handling
- Namespace Handling Considerations
- Namespace Handling BC Break
- Trait Handling Refinements
- Trait Abstract Signature Check
- Private Abstract Methods in Traits
- Private Abstract Methods in Traits
- Variance Support
- Variance Support
- Covariance
- Contravariance
- SPL Differences: SplFileObject
- SPL Differences: SplHeap
- SPL Differences: SplDoublyLinkedList
- SPL Autoloading: spl_autoload_register()
- Lab: Core OOP Coding Differences
Procedural Programming Differences
Prior to May 2000, when PHP 4 was officially released, all PHP programming used what is now referred to as _procedural_ coding style. Procedural programming is distinctive in its extensive use of libraries of _functions_ rather then OOP classes. In this unit we focus on PHP 8 changes to procedural programming.
This unit includes the following topics:
- Procedural Programming Differences
- Differences in String Handling
- Non-Well-Formed Numeric Strings
- Numeric Strings BC Breaks
- Numeric Strings BC Break Examples
- Comparison Madness
- Comparison Examples
- String Handling: Needle Argument
- Differences If No Needle
- v*printf() Changes
- substr*() NULL Length
- Crazy Uncle implode()
- Second Param parse_str()
- Locale Independent Float-to-String
- Locale Independent Float-to-String
- No More Function Overloading
- Function Overloading Example
- Array Handling Differences
- Array Curly Brace Usage
- Hello, Operator?
- Non Scalar Operands
- Constants Are Now Constant
- File Handling
- Function Differences
- Disable Functions
- Disable Functions Example
- Security Related Function Changes
- Security Function Change: assert()
- Security Function Change: password_hash()
- Security Function Change: crypt()
- URL Handling Changes
- Misc Changes
- Changes Pertaining to Windows
- Lab: Procedural Programming Differences
Extension Gotchas
In addition to changes to the PHP core, there have been significant changes to a number of PHP extensions as well. In this unit we identify critical changes in key extensions and things you need to watch out for to avoid BC breaks.
This unit includes the following topics:
- Extension Gotchas
- Objects Rather Than Resources
- Objects Rather Than Resources
- Objects / Resources: XML Parser
- XMLWriter Differences
- CURL Extension Gotchas
- Mbstring Extension Gotchas
- Mbstring Extension Gotchas: mb_ereg*
- Mbstring Extension Gotchas: mb_ereg*
- Mbstring Extension Gotchas: mb_strrpos
- Mbstring Removed Aliases
- Mbstring Extension Gotchas: Other
- PCRE Extension Gotchas
- PCRE Extension Gotchas Example
- Intl Extension Gotchas
- Database Extension Gotchas
- PDO Gotchas
- GD Extension Gotchas
- GD Extension Gotchas
- Reflection Extension Gotchas
- Reflection Extension Gotchas
- Reflection Extension Improvements
- Zip/ZipArchive Extension Gotchas
- ZipArchive
- ZipArchive Example
- Misc Extension Gotchas
- Lab: Extension Gotchas
New Cool Stuff
This is the part you all have been waiting for, right? The new **cool stuff**. Without further ado, let's roll!
This unit includes the following topics:
- New Cool Stuff
- JIT Compiler
- JIT Compiler: How to Enable
- JIT Compiler: Controls
- JIT Compiler: Controls Continued
- JIT Example
- The Case for Union Types
- Union Types: Syntax
- Union Types: Exceptions
- Mixed Types
- Mixed Types Example
- Mixed Types Impact on Variance
- Mixed Types Impact on Variance
- Weak References
- Weak Reference Example
- Weak Map
- Weak Map Usage Example
- Variadic Operators
- Nullsafe Operator
- Nullsafe Operator Short-Circuiting
- Match Expressions
- Match Expressions: Considerations
- Match Expressions: No Silent Coercion
- Static Return Type
- Named Arguments
- Named Arguments: Order Independence
- Named Arguments: Skipping Defaults
- Attributes
- Attribute Syntax
- Simple Attribute Example
- Attribute Use Case: Original
- Attribute Use Case: Revised
- Attribute Class
- Constructor Argument Promotion
- Constructor Argument Promotion
- Lab: Cool Stuff
Lots of Improvements
There have been many improvements in syntax and general handling of classes and functions in PHP 8. A number of improvements were actually first tested in PHP 7.4, and fully implemented in PHP 8.
This unit includes the following topics:
- Lots of Improvements
- Typed Properties
- Typed Properties
- Typed Properties
- Arrow Functions
- Arrow Functions
- Arrow Functions
- OOP Syntax Improvements
- Uniform Variable Syntax
- What's "De-Referencing"?
- Uniform String Dereferencing
- Dereferencing Constants
- Expressions Anywhere
- Extended Use of ::class
- No Comma Left Behind
- JSON is Here to Stay!
- Try/Catch/Finally New Stuff
- array_splice() Improvements
- array_splice() Example
- array_slice() Performance Boost
- array_slice() Example
- String Handling Enhancements
- Stable Sorting
- Stable Sorting Example
- Affect on Keys in Stable Sorting
- Illegal Sort Functions
- Strings: Beginning, Middle and End
- Strings: Beginning, Middle and End
- Strings: str_contains
- SQLite Authorizer
- Other Improvements
- Other Improvements
- Other Improvements
Cool Stuff in Extensions
As well as core additions, there have been a number of incredibly use enhancements in a number of PHP extensions. This unit focuses on new and cool stuff in PHP 8 extensions.
This unit includes the following topics:
- Extension Cool Stuff
- OpenSSL Improvements
- New Tokenizer Class
- New Tokenizer Class
- Security Filtering Improvements
- Improvement in Timezone Change Handling
- DateTime Creation
- PHP Web Extension Improvements
- Miscellaneous Extension Improvements
- Lab: Cool Stuff in Extensions
Error Handling Improvements
Error handling has been strengthened in PHP 8. As many of you have observed during the transition from PHP 5 to PHP 7, error handling was improved. With each successive release of PHP 7.x, you also observed that bad programming practices are slowly being restricted. PHP 8 goes one step further, as explained in this unit.
This unit includes the following topics:
- Error Handling Improvements
- Warnings Promoted to Fatal Errors!
- Warnings Promoted: Array
- Warnings Promoted: String
- Undefined Constants Now Fatal Errors
- Notices Promoted to Warnings!
- Error Level Defaults Changed
- Use of Parent
- No Longer @Silent
- Using @ Operator With error_reporting()
- Inheritance and Method Signatures
- Error Related INI Directives
- Compile Time Warning Changes
- Clean Shutdown
- Non Capturing Catches
- Lab: Error Handling
Going, Going ... Not Quite Gone
Using classes, methods, functions, etc. on the _deprecated_ list are not going to break your code, however it's an indication that at some point in the near future these constructs will be removed from the language. Accordingly, it's important for PHP developers to at least be aware of the more important deprecated functionality in PHP 8.
This unit includes the following topics:
- Going, Going ... Not Quite Gone
- Core Deprecations
- Deprecations: Enchant
- Deprecations: Reflection
- Things Removed
- Each What, You Say?
- __autoload: Loads No More
- Removed Classes
- Security Related Removals
- Removals Related to Extensions
- Misc Extension Removals
- Lab: Deprecations