The PHP 8 Match Expression (0m 17s)
Samuel Adeshina: Another interesting one is the match expression. So if you are somebody who uses the switch/case blocks a lot, then you’ll find this a life saver because what the switch case statement helps you to do is to check for the different values of a particular object or variable can have and run specific blocks of code through them.
But those values must have the same properties, for instance they must be of the same type. You can’t have multiple checks at the same time and all of that.
So what match helps you do is you get to check different values, different options irrespective of whether they are similar or not have the same properties and you get to use this to achieve a similar thing.
You would have using a switch statement. So this can really go a long way to help you avoid having if/else statements within switch blocks because sometimes you want to write a switch block and within a case statement.
You need to check if the value you are checking is of a particular type of a particular property. So the case the match expression would strongly help you to avoid that.
So this is useful in a lot of ways but it all depends on you and your style of programming. As we said it is a syntactic sugar to really make your code more intentional.
I really love PHP 8 because that is what I feel it strives to make you actually write things the way they are meant be.
Manuel Lemos: Yeah. Well again this is another aspect of the language that you can change your programming habits: switch from this style to this style. It’s up to you.
Although this number of lines seem to be longer they have lots of empty spaces and lines that could be combined into single one.
It’s a difference more in style than in time that you need to type to do the code. What looks smaller here it’s not that different here. It’s just it’s spread out to more lines.
Anyway it’s a new feature. It’s optional. You use it if you like it. It’s up to you. If you don’t see the advantage in using it, it’s up to you.
Usually new features are better to use in newer projects because new projects will start with new code and new code will be the code that will be used in the new projects and you probably need to implement new tests that test the new code that use the new style.
So it’s a lot of new things. And the as I’ve been commenting with Samuel before, the first time that you try to do something new, there is a great chance of making mistakes.
You are human like ourselves. We are born to make mistakes but it’s acceptable to do a mistake once, maybe twice, but then you need to fix yourself.
Samuel Adeshina: It’s not a guy mistakes. It’s the habits if it happens another time.
Manuel Lemos: And a mistake is not really something that is wasted because you can always learn from your mistakes. What may be a waste is that you insist on the same mistake forever.
So it’s up to you to evolve and adapt. Also a word of advice if I may, if you allow me. People are insisting: oh you need to move on to the new versions.
You are set in the past because you still use the old versions. Sometimes it’s not under the control of the programmer. It’s more in the control of the company that hires the programmer.
They are the ones to decide if they switch to a newer version of PHP or not. And sometimes they do not decide to move on because the work that needs to be performed to do the migration is a lot of work and that work costs money.
So sometimes they are saving money by not upgrading. When they avoid upgrading it’s because their budget is limited. So you need to be tolerant and do not push people to always upgrade.
That’s why that I suggests that you use new things on newer versions. Older versions, let’s leave them stable working, unless there are some backwards incompatible change that makes that old code stop working.
Do not bother insisting on your preferred style just try to persuade people though this style is better because there are disadvantages.
But if other people disagree it’s okay . That happens every time in your life.
How to Buy the Official PHP elePHPants (6m 06s)
Manuel Lemos: And we are practically ending this podcast. And it’s up to you. This is just one episode of the Lately PHP podcast on which we are talking about PHP 8. We will also talk about other aspects.
What I would like to say to end this podcast if you allow me, we are doing this podcast is also work, work of collaboration we are not asking anybody to pay us.
We are doing this because we have fun. We are doing this as a part of the content that will be published in the PHP Classes site, as well in YouTube.
And what we would like, if you allow us, is that if you would like to support not only the PHP community as a whole but also PHP Classes, is try to find these in the PHP Classes just to show…
Samuel Adeshina: The best stress relief you need as a PHP programmer.
Manuel Lemos: …this is the official PHP ElePHPant that was allowed to be produced and sold, by Vincent Pontier from France, the creator of the design. Actually, there one improvement, like PHP 8, think about this is the PHP 7 ElePHPant. The PHP 8 is more like this.
This is the the pink, as you may see. And we are going to also make available the possibility to personalize your elephants with maybe your name, like Carolina, and oh this is the PHP Classes also. These are optional. Actually you need to do extra work to pay that cost a bit more.
And one possibility is this to have the PHP 8 logo. There this is also a design of Vincent Pontier.
We are very, very grateful for him and for his kindness. He’s been supporting the site for many years. Not only he allowed us to produce this one but also the previous one which was also an improvement from a contributor of the site.
And we want actually to pay him royalties and he was being kind enough to waive those royalties. And all the money that we can get to to the site is reverted to continue further development.
Upcoming PHP Classes Marketplace (8m 50s)
We want to pay more contributors, more PHP developers to help us to improve the feature that many developers want. Oh I would like the PHP Classes to be better.
And PHP Classes will be better in a way that I hink many people will like, which is, we are going to help developers to buy and sell their own software products written in PHP or maybe APIs or components or courses, many things that will be announced soon and are part of a plan that we have been executing very slowly but is moving on every day a single bit until we get there.
So we hope in the next months we open the PHP Classes marketplace which will be like many markets that are out there on which can help you, Samuel, or other people to have their products be sold in the market.
Conclusion (10m 02s)
So basically that’s it. I would like to thank you for the opportunity to listen to us. And hopefully we have provided value in terms of knowledge about the new features of PHP 8, as well features for the upcoming versions of PHP, by versions I mean the other features that PHP 8 has implemented.
And on my behalf that is all for now. I’ll like to leave you with the last words from Samuel. Last words for now. He is not going to die okay?
Samuel Adeshina: Thank you for this episode about PHP 8. And I would just encourage you to check it as soon as it is released which is hopefully in less than two weeks from now.
Manuel Lemos: OK. Let’s see us again soon. If you would like to propose topics or even participate in the podcast with us, just contact us. We’re going to make available the contacts.
We are very accessible and anybody can contact us. Send us emails. Send us spam. Send us complaints. Send us complaints. Send whatever you feel it’s right for you to comment. So we will be waiting for your comments, or not, it’s up to you. On my behalf that is all for now. Bye.
Samuel Adeshina: Thank you. Thank you. Bye.