Urgent PHP #1: generics, mago, the pipe operator, the action pattern, and brent prefers pest
· Summarized
Key takeaways
- PHP generics are a critical upcoming feature, primarily aimed at static analysis, with the RFC promising native syntax that won't impact runtime performance.
- Ecosystem players like Laravel, WordPress, and Drupal could benefit significantly from native generics, leading to better code understanding and maintenance.
- Static analysis tools like PHPStan, Psalm, Mago, and PHPStorm currently have inconsistencies, but future standards and tools will improve interoperability and accuracy.
- Security in the PHP ecosystem, especially concerning composer and package integrity, is steadily evolving, with new features like cooldown periods, malware checks, and multi-factor release confirmation.
- The Action Pattern offers a clear, maintainable approach to application logic, favoring explicit, testable units over event-driven architectures that can become complex.
- Advanced testing, including browser testing with Pest PHP, is rapidly progressing, enabling end-to-end testing in PHP that closely resembles real user interactions.
- The PHP community is hosting PHP Verse, a large online conference, to showcase diversity and innovation within PHP, emphasizing community and collaboration.
Summary
Introduction and Hot Topics in PHP
The hosts introduce the podcast, emphasizing that while there is no real urgency, they will discuss pressing topics in PHP. The conversation starts with PHP generics, exploring their current state in PHP 8.6, the ongoing RFC, and the importance of static analysis tools like PHPStan and Psalm. They highlight that PHP generics are about enhancing static analysis rather than runtime type checking, and discuss the proposed syntax for generics, comparing it to how Python implements generics. The benefits of generics for static analysis, code inference, and ecosystem adoption are emphasized.
Generics in PHP and Ecosystem Impact
The discussion explains that PHP currently relies heavily on annotations for generics, with tools like PHPStan and Psalm interpreting them, and that the new RFC aims to bring native generics support without runtime overhead. They compare PHP's approach to languages like Python and TypeScript, describing how this could benefit frameworks like Laravel and WordPress by integrating generics seamlessly. The speakers advocate for this RFC as a crucial step toward making PHP's type system more powerful and integrated, stressing that failure of this RFC might delay generics in PHP indefinitely.
Static Analyzers and Ecosystem Tools
A comparison of static analysis tools—PHPStan, Psalm, Mago, and PHPStorm—is discussed, pointing out inconsistencies and gaps due to lack of a single specification for generics in PHP. Mago is highlighted as an emerging, fast, Rust-based static analyzer that is gaining popularity. The benefits of advanced tooling, including types of analysis (mutation, browser testing, parallel testing), are discussed, along with future developments expected in PHP testing frameworks like Pest.
PHP Security and Package Management
The hosts focus on the rising importance of security within the PHP ecosystem, especially regarding composer and package security. They discuss recent improvements such as package release cooldowns, malware detection via Akito, and better package verification, including two-factor authentication visibility. The conversation underlines the critical need for multi-factor confirmation before package distribution, suggesting a future security model that involves package authors receiving release confirmation prompts. The PHP Foundation’s new security initiative and the importance of layered security measures are emphasized.
The Action Pattern and Application Design
Brent shares his motivations for developing the Action Pattern, motivated by a real-world CRM project and inspired by functional programming ideas. The pattern involves small, invocable classes (actions) that encapsulate individual business logic steps, making code highly testable, composable, and explicit without side effects. Both Brent and the host discuss how the pattern helps maintain and understand complex applications compared to event-driven approaches, which tend to become difficult to maintain over time.
PHP Testing Frameworks and Browser Testing
The conversation shifts to testing tools, with a focus on Tempest PHP, which integrates with Mago for code quality and whether to use Pest or PHPUnit for testing. The hosts discuss the power of browser testing in Pest PHP, utilizing real browsers like Chrome, and the exciting upcoming features in future versions of Pest, promising state-of-the-art testing capabilities. They highlight how these tools enable comprehensive end-to-end testing experiences that closely mimic production environments.
Upcoming PHP Conference and Wrap-up
Brent talks about PHP Verse, an upcoming online conference showcasing the PHP community's diversity with speakers from Laravel, WordPress, Drupal, and Symphony. The event aims to demonstrate PHP's vibrant ecosystem and will be live streamed on YouTube, with fun activities like Lego elephant giveaways. The hosts conclude by inviting listeners to participate and share feedback on the podcast format, expressing enthusiasm for future episodes.
Sponsors
- PHP Annotated · Brent's channel hosting PHP Verse, an online PHP community conference with diverse speakers from the PHP ecosystem, live streamed on YouTube. They are giving away Lego elephants during the event.
Show notes
the first episode of urgent php is out
just hot php topics for 30 minutes straight: generics, mago, the pipe operator, the action pattern, and brent switching to pest
Follow this show on AudioBrevity and new episodes get summarized for you. Create a free account