![]() You have matching this variable against a set of expressions just like you would switch, whereas a few major differences with switch here. Derick Rethans 3:34 How's the match expression going to solve all of this stuff? Derick Rethans 3:37 The match expression is a new language keyword, but also allows you to switch depending on a condition matching a variable. ![]() So it's totally okay to have case statements, and then not have a condition for a specific type and switch doesn't require you to add default at the end either, so you can actually have having a condition that would never match any case, and you have no idea that that would happen. And another but minor issue with switch is that it is okay not to cover every value with a condition. And then, what you really want to do the result of, depending on which case is being matched, assign a value to a variable and the current way how you need to do that now is case, say case zero result equals string one, break, and you have case two where you don't set return value equals string two and so on and so on, which isn't always a very nice way of doing it because you keep repeating the assignment, all the time. It's not a common thing to use it switch is that we switch on the variable. If you forget, then some weird things will happen sometimes. Now sometimes that is something that you want to do, but in many other cases that is something that you don't want to do and you need to always use break. ![]() At the end of every case statement you need to use break, otherwise it falls down to the case that follows. And one of the cases has case zero, and it will still be matched because we put type equal to zero, and that is of course not particularly useful. And this operator as you probably know, will ignore types, causing interesting issues sometimes when you're doing matching with variables that contain strings with cases that contains numbers, or a combination of numbers and strings. So the first thing is that it matches with the equals operator or the equals, equals signs. But switch has a bunch of different issues that are not always great. And then for each of the things that you want to match against your use: case condition, and that condition can be either static value or an expression. So you have to switch statement: switch parentheses open, variable name, parenthesis close. Switch is a language construct in PHP that you probably know, allows you to jump to different cases depending on the value. Derick Rethans 1:07 What a coincidence! Derick Rethans 1:10 So what is the problem that is RFC is trying to solve? Derick Rethans 1:13 Well, before we talk about the match expression, we really need to talk about switch. Derick Rethans 0:53 Hi Derick, would you please introduce yourself? Derick Rethans 0:56 Hello, I'm Derick and I'm the author of Xdebug I'm also PHP seven four's release manager. ![]() This is probably going to sound absolutely stupid, but I thought I'd give it a go regardless. As I think it's important that we talk in some depth about all the new features in PHP eight, I decided to interview myself. I have asked the author of the match expression RFC, lija Tovilo, whether it wanted to come and speak to me about the match expression, but he declined. ![]() Today we're going to talk about a match expression. Transcript Derick Rethans 0:15 Hi, I'm Derick, and this is PHP internals news, a weekly podcast dedicated to demystifying the development of the PHP language. In this episode of "PHP Internals News" I chat with Derick Rethans ( Twitter, GitHub, Website) about the new Match Expression in PHP 8. Thursday August 20th, 2020 - 09:30 BST Description ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |