PHP 8.6 Full Review: Pattern Matching Under Discussion, Clamp & Partial Functions Accepted
Chapters9
Introducing pattern matching as a more elegant alternative to multiple conditional checks, making status comparisons simpler.
PHP 8.6 brings pattern matching with an is keyword, a native clamp function, partial function application, better JSON error reporting, and more—and generics may still be brewing.
Summary
Nuno Maduro breaks down what PHP 8.6 could deliver, highlighting pattern matching as a potential game changer and noting that generics may or may not land this cycle. He shows how the new is keyword would let you write cleaner checks like if the given status is done without long match chains. The discussion then widens to other confirmed or likely features, including a clamp function that constrains values between a min and max, and the ongoing work on partial function application that promises easier closures and pipe-style workflows. He also demonstrates improved error localization for JSON payloads, pointing to the exact problem position instead of a vague syntax hint. An embedded enum for sort direction is presented as an example of language-level conveniences, though he argues such things might be better placed in user land. Reflection receives a light-touch improvement: you can check if a property is readable or writable more easily. Throughout, Nuno emphasizes this release’s potential impact, while clearly noting that some features are still under discussion or not yet merged. If you want the full depth, check the RFCs linked in the description and ride along for the verdict on 8.6’s biggest punchlines.
Key Takeaways
- Pattern matching gains a dedicated is keyword, simplifying status checks (e.g., if the given status is done).
- Array shape/type checks enable shape matching like A is a string, B is an integer or float, and C is either foo or bar.
- Clamp provides a native min/max guard, e.g., 150 between 0 and 100 becomes 100.
- Partial function application promises simpler closures and improved pipe usage by swapping the latest arguments with a ? placeholder.
- JSON decoding errors will point to the exact location of the problem in the payload, not just a generic syntax error.
- A built-in sort direction enum is introduced for cleaner match-based direction handling, though it’s suggested as potentially better in userland.
- Reflection gains a straightforward is_writable/is_readable check to inspect property access rights at runtime.]","target_audience":"Essential viewing for PHP developers who want to understand the practical implications of PHP 8.6, especially those curious about pattern matching, value clamping, and better error reporting before upgrading. This video is also helpful for teams weighing which language features to rely on in production and how future changes may affect existing codebases.","topics":["PHP 8.6","Pattern Matching","is keyword","Clamp function","Partial Function Application","JSON Decode Error Location","Enum (Sort Direction)","Reflection","Generics (uncertain)"],"key_quotes":[{"quote":"so you can effectively do something like if the given status is done, then I do this.","timestamp":"00:01:20","context":"Illustrates the new is keyword idea replacing nested match logic."},{"quote":"The array shape story is literally a massive improvement versus what we had before.","timestamp":"00:02:15","context":"Highlights the new shape-based array/type checks."},{"quote":"The new native function called it clamp.","timestamp":"00:03:05","context":"Introduces the clamp feature and its practical use."},{"quote":"JSON decode a payload, but then you have no idea where the problem actually is.","timestamp":"00:04:15","context":"Points to the improved error location feature in PHP 8.6."} ],"related_questions":["How does PHP 8.6 pattern matching with the is keyword differ from previous match usage?","What exactly is the clamp function in PHP 8.6 and how do you use it?","What is partial function application in PHP 8.6 and when would you use the ? placeholder?","How will JSON decode error location improvements help debugging PHP payloads?","Should I rely on generics or pattern matching in PHP 8.6, or wait for userland implementations?"
Who Is This For?
Essential viewing for PHP developers exploring what PHP 8.6 might bring, especially around pattern matching, clamp, and developer tooling improvements. Great for teams planning upgrades or evaluating new language features against existing codebases.
Notable Quotes
"so you can effectively do something like if the given status is done, then I do this."
—Demonstrates the is keyword replacing verbose match logic.
"The array shape story is literally a massive improvement versus what we had before."
—Talks about the new, more powerful shape/array matching.
"The new native function called it clamp."
—Introduces the clamp feature and its purpose.
"JSON decode a payload, but then you have no idea where the problem actually is."
—Explains improved error location in 8.6.
Questions This Video Answers
- How does PHP 8.6 pattern matching work with the is keyword?
- What is the clamp function in PHP 8.6 and how do you use it?
- What is partial function application in PHP 8.6 and how does it affect closures?
- How will PHP 8.6 improve error reporting for JSON payloads?
- Will generics or more pattern matching land in PHP 8.6 or later?
PHP 8.6Pattern Matchingis keywordClampPartial Function ApplicationJSON Decode Error LocationEnum: Sort DirectionReflectionGenerics (uncertain)
Full Transcript
What's up everyone? Welcome back to another video. Today we are going to talk about PHP 8.6 which is coming out by the end of the year. My name is Nuno and welcome to my channel. All right, the first thing worth to mention is that generics may or not actually come for PHP 8.6. I have a full video on that topic right here. Well, not right here, but on a comments below. Now, generics are cool, but this one is actually even more sexy. It's called it pattern matching and effectively makes the match statement super useful. Let me show you.
If I want to see if some given status for example is from the status to do done, I had to do this match true and then I had to triple equal the thing and it's yuck. I don't like it. Now, in PHP 8.6 this problem will be entirely fixed by introducing this new keyword called it is. So, you can effectively do something like if the given status is done, then I do this. This is way more sexy than what we had before. [music] Besides fixing the match statement, this RFC also fix like PHP in general.
I love how can you now do something like if this given var is a string, you can just do var is string or you can do something like if this var is an integer or float. This is beautiful by the way, okay, when compared with things like we had before. When you go through the RFC, this gets even more wild. You can do stuff like if the given var is hearts or spades for example, which is literally strings. You can also do something like if it's this or that or potentially like a constant. You can do something like if this given var is less than 10 or more than five.
This is absolutely dope. Besides fixing the match statement, we also see things like if the given list is exactly of this shape. This is such a beautiful thing coming to the PHP language. And this array shape story is literally a massive improvement versus what we had before. For example, you can now literally check if the given associative array is from the given shape. A is a string, B is an integer or a float and C is either foo or bar. This is a massive improvement on the PHP land. Now, this is under discussion, so it may not actually come on this precise PHP version, but might come later in the future.
I love it. Check out the RFC on the links below. The next feature is called it clamp. It's actually something that solves real-world problems that we have every day as PHP developers, so let me show you. How many of you have wrote code like this? You basically have a value and you want to make sure the value is between something and something, so you have to do this crap all [music] the time. Minimum and max, it just PHP 8.6 is finally fixing that issue by introducing this new native function called it clamp. And clamp is going to make sure that the given value is between the given minimum and the given maximum.
So, if I were to do 150 between 0 and 100, of course, PHP 8.6 will make sure the value is 100. Next big feature coming for PHP 8.6 that is already accepted. Okay, so if I go all the way down, we see a bunch of approvals, as you can see here. The next big feature is partial function application, which is accepted, but not yet implemented on the core. It's not yet merged. Let's see what this is about. In PHP, you always had this beautiful way of creating a closure. So, you can literally say the slugify closure will accept the given string and then replace the given space with this beautiful character to have this closure.
Now, for PHP 8.6, this will be massively simplified. If you want the closure behaves exactly like the string replace, however, you just want to swap the latest argument, you can now use this question mark. And you have literally a closure that you can use to buy your groceries. This will effectively fix the pipe operator because everyone was excited about the pipe operator, but once they saw they need to do this kind of crap, they were like, "No way, I won't use the pipe operator." So, now what you can do is literally do something like this.
I'm going to buy groceries, okay, as a string, and then I'm going to trim it, and then I'm going to string replace the last character by string to lower it. So, you can effectively use the pipe operator with much more easiness. Next feature, we didn't have an RFC because it's just common sense that it's something that needed to be fixed. Let me show you. How many of you have literally tried to JSON decode a payload, but then you have no idea where the problem actually is. It literally happens all the time. You know that it's a syntax error, but you don't get pointed to the exact location of the payload where the problem exists.
Here we know the payload literally exists on this exact problem right here, but the actual code at runtime won't tell you that. Now, on PHP 8.6, this is getting fixed. You literally finally get this fixed by having PHP pointing you to the right location. So, here for example, we note that the character 41 has an issue, which is this beautiful comma. So, if I run this code, check it out. I have literally having PHP pointing me to the right location. Beautiful stuff. Next one is this new enum called it sort direction, which is a built-in enum on PHP.
Now, my opinion is that this kind of stuff shouldn't live on the language itself. It should actually be user land code, but they are now introducing this enum that you can use in your beautiful PHP code. Meaning that if you have a match statement that you want to kind of do separate things depending off the given direction, you can do, "Okay, if my direction is ascending, then you do this. If my direction is descending, then you do that." I don't know. I think this kind of stuff should live at user land. Let me know in the comments below what do you think.
Next one is actually a new reflection method. It's a little bit advanced, and you probably shouldn't be use it, but you can now through reflection know if a given property is readable or writable. You know, right? We have like this read-only keyword coming on PHP 8.4 or 8.3. It doesn't really matter, but you can now use reflection to effectively check if the given property is readable or writable. So, on this example, we have this to-do class, and if I want to know, for example, if the given owner through reflection is actually writable or not, I would have to obviously do a reflection property, so this is no different.
Okay, we had to do this before and you have to do this right now. But, we would have to do something like this. Just looks weird. I have to just get the modifiers and then do that. Yuck, it's ugly. This is like old PHP. PHP 8.6 will be much simpler. You can just use this is writable and have access to that information. Bam! So, we have a lot of cool things going to PHP 8.6 including clamp, sort direction, JSON decode, partial function application. So, all of this stuff is awesome, but we don't know yet if pattern matching or generics are coming.
I honestly think if one of them goes to PHP 8.6, this will be probably the biggest PHP release ever. I cannot wait for PHP 8.6. If you guys enjoyed this video, please go all the way down, click on the like button, subscribe to the channel. Love you all. Catch you guys next time. [music] And it's done.
More from nunomaduro
Get daily recaps from
nunomaduro
AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.




