PHP Doesn't Suck Anymore? | Prime Reacts

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
let's do this every time I make a video on PHP which is basically all the videos I make I get the exact same comment dead PHP sucks all the time every time and most of the people that think PHP is dead haven't looked at PHP since like 2012 which is okay so maybe he is saying exactly my experience which is I haven't looked at PHP since 2012 2013 I think the last time I kid you not I was such a PHP dork that in 20 13 there's get there's Go I mean node was technically taking off I started a new project I this was back when I was trying to do startups I was always trying to do little tool startups and all that and uh I started a new project using tortois SVN and PHP okay 2013 I did that in 2013 I want you to know that right now because if you don't know that you just don't understand how painful my life was I didn't know about all these cool things you know this is back in back in that day when I wasn't I wasn't in my exploratory phase but nonetheless tortois SVN in the day of get 45.4 came out and listen things were a lot different in 2012 I had just graduated college a degree in accounting for some reason this guy was still the president over here this mov many and honestly pretty good movie our music okay first off can we just agree that Looper was actually a pretty good show okay whatever that guy's name is Joseph Gordon Wyatt levit something like that I like him okay I loved him on Third Rock From the Sun okay I loved him there Tommy I believe was his name and I I love it now okay yeah I like it Bruce Willis okay actor but Joseph Gordon Wyatt levit whatever his name is loved him went through this real weird hey ho phase where we were always shouting hey ho in the songs hey I think it's safe to say that a lot of I'm no longer an accountant and PHP no longer sucks I'm going to run you through a bunch of the language changes that have happened since around 2012 when PHP 5.4 came out and stick around to the very end because we're going to talk about types we got to talk about type safety every time I talk about PHP people just say yeah I just need types we got to have types what about types do you guys have tipes like yes this is me I'm this person I'm literally that person are you winning son are you winning son no I am not winning son I must have types it's the same reason why I didn't choose Elixir as my first functional language but instead o camel because o camel is a very strict beautiful static typing language and so this is like this I've always had this problem uh I do want to follow up on one more thing he said that I was such a PHP Fanboy and that was during the height of my like maximum hours I worked per week I was doing like 80 hours a week of PHP 5.4 or whatever it was I was into PHP so I'm actually excited to see the new things that have happened to PHP since then and can I like feel that it's a good language I don't know I don't know I'm willing to have my mind remain open for this can't leave my types we've got types so I'm going to show you all the different types you can do at the end let's take PHP beat JavaScript to types you should feel bad about yourself if the language in which the original author said it should have never been a language was able to beat you to types you should feel bad about yourself okay you came out like this just feel bad take a look at these changes going all the way back to 2012 for this one PHP 5.4 included traits so instead of writing the same method body over and over and over or instead of abusing inheritance we now have composition so you can have traits and include those in every class what oh sh I think I like PHP oh my goodness what favoring composition over inheritance PHP is actually better than JavaScript I can't even believe it it's real it's real look I even put my name in there what a nice guy short array syntax imagine writing out the word array like a caveman when you can just use square brackets short array syntax allows you to use square brackets thank you very much let's go thank you we now have array destructuring it used to be that you have to assign an array to a temporary variable and then reference those Elements by index if you wanted to assign them to other variables now you can just use array destructuring and D PHP actually is it's going to is it really going to be a good language this trait thing just blew me away and now they're just doing basic conveniences for every developer this is good this is good like PHP welcome welcome to Modern programming I like what I'm seeing directly assign the variables from the array we have first class vartic functions so you can pass as many arguments to a function as you want using this I don't know how I feel about vartic arguments I keep going back and forth on them like if they're a good idea or a bad idea I never know do you know what I mean like do I like them or do I not like them because ultimately whenever I get to vartic arguments I almost always want to use a function with an array as AO or a list as opposed to actually spelling out the arguments one by one I almost never actually want vartic arguments like almost never Almost Never there because any anytime you're doing something programmatically you almost always this right here right you almost already have the nums array and now you have to dot dot dot yeah print f is a good example where it's really really good but print f is unusual you don't really use like formatting functions I'm on for vartic stuff I can completely concede that ground and things like formatting or string uh uh like rope string generation anything like that totally on board with that dot dot syntax speaking of dot dott dot syntax you can use that same syntax to spread or Splat an array into an argument list for a function ddy you use that same syntax to spread or Splat an array into another array so if you want to take all the items from one array and put it into a second array you can do that again this is very very good also very very interesting uh because this is a great way to create a lot of memory on accident that with this spread operator we now have generators if you want to do something memory intensive but in a memory efficient way you can use a generator so if you need to read a huge file you don't have to load that whole file into memory you can use a generator to yield it line by line by line if you ever need a new class but can't be bothered to make a new file who has the time you can create an anonymous class an an let's go I love that I love this idea that that classes are just as much first class citizens as functions this is great this is great because there are times where you just don't want to do that and you really just need this right here this is great this is actually great wow PHP has aous class can Implement an interface okay I you know we're pausing this for a quick second I'm hopping over to Twitter and maybe PHP isn't all that bad anymore I am I'm we're shook okay we're shook right now we're shook Oh no just like every other class so this is a great use case for when you need one stupid little implementation but you don't want to make a full class for it yeah this is a big one I need you to pay very very close attention we now have trailing commas in function calls so look very closely at email look at the very end of the word email and watch what's about to happen oh oh my goodness oh boy I actually just added a brand new emote just last night there you go thank you can we get some WS in there we need some wets that this is just what I want this is what I want can we get some WS I I need I need it I feel it this is wet ass programming going on right now oh my my goodness oh my goodness what oh love it I love it I love it amazing we now have trailing commas in method calls PHP rules this one's for all okay well okay trailing commas ain't making PHP rule but I okay I'm on your team though it's pretty nice okay my JavaScript friends I know you love your arrow functions well look out friends we've got Arrow function to RS honestly are well they're they're a little bit worse I don't like the FN at the beginning to denote that it's a function but hey we were I actually like the FN at the beginning real talk I like that I actually I I've never really loved the Aros syntax I like the idea of it being very consistent I like this this is perfectly fine with me this is beautiful work with what we've got we have short short closures or Arrow functions php7 brought us the null coalescing operator so we can say the username is equal to the username unless the username is null in which case we'll go with guest so we have this nice neat null coalescing operator but we also have the null coalescing assignment operator which can shorthand all of that and say if the username is set leave it alone otherwise set it to guest I understand what a PHP gasm is I think I just had multiple PHP gasms in a in a matter of minutes okay I don't know what's going on here but we're gming okay whatever it is it's happening right now it's happening speaking of nulls we used to have to do something like this we would pull the birthday off of the user and then before we were allowed to call a method on birthday we would check to see if birthday existed yep you don't want to call a method on null but now we have the null chaining operator and we can just say if birthday is not null call the format function on it if it is null just stop the chain right there we have named arguments now it used to be that if you wanted to skip over an optional argument you had to leave a null in the position of that argument but now we can just name our arguments and pass them in any order that we want PHP has attributes now which in other languages are probably called annotations but you can add an annotation I actually like this okay I like that I don't care what you have to say okay you come in here with your oh PHP is becoming C okay first off PHP doesn't have a history of Triple E actions slash they didn't give us the world they didn't give us vs code I mean they did give us WordPress which one could argue is worse than vs code but nonetheless look this looks great okay I love this kind of stuff this kind of stuff to me is fantastic I've never had a huge problem with this uh because you know at the end of the day you you have this you have this whole problem with like go you have to like specify everything and it can kind of look a little you know I'm over here maybe my go is not that great yet I you know I but you know this kind of stuff where you're just like doing this you know I I don't know how I feel about that either you know what I mean to a class or meage or an argument or property you can add an annotation to almost anything and control a little bit of behavior that way keep this in mind we're going to look at this again in a second this one is just a huge massive Improvement it used to be when you were catching an exception you had to have a variable for that exception even if you weren't going to use it even if you were just simply going to return false you had to have that little e in there now look at this watch this watch that e amazing no longer needed if that's not reason enough to switch to PHP I don't know what to tell you remember those attributes that I told you about literally two seconds ago there's an attribute that will will mark an argument as sensitive and redact it from all stack traces so you don't accidentally end up logging something you shouldn't at a language level very okay that is genuinely awesome this is genuinely awesome this is actually okay so this is one of those things that I I I I would say is is super cool that is super cool can we all agree that that is out of out of this world this is this is great weird and probably very slow maybe uh maybe it's only slow on the exception case one could imagine that it's slow purely on the exception case right uh and it has no real world imp implications on uh on performance in any sense cool look at this switch statement it's hideous it's huge we hate it what we're doing is we're switching on a status code and then in the body of every status we're setting a message variable there's got to be a better way there is a better way we can use the match statement now and assign the message message variable to the result of the match statement and look at 200 300 we can have multiple matches return the same thing this is a much more compact much more readable way to write a switch statement that assigns a variable we've got weak Maps now did you know that PHP has weak maps you can set an object as a key in a weak map where you can't you can't do that in an array and also weak maps are way better for memory because they'll get garbage collected when there's no references to that object anymore PHP now has enums so you can have an enum class where you delineate the cases inside the body of that class and those enums can also have a value so if you want to use the words draft published and archived in I mean this is this ain't that that impressive okay you know like you've been like I've been having nothing but i' I've had however many section gasms that are available and then you just hit me with a basic enum this this ain't it okay this this this a this ain't impressing me right now your codebase but you want to use the value use 1 2 and three in your database you can do that with a backed enum that's not all that enums can do you can add methods to your enum classes in this case We'll add a method that gives a userfriendly display to each of the using the match statement again and we're just matching against this and all of our cases are our enum cases one of the great things about having I mean it's still better than typescript enums can we all agree that somehow typescript enums are actually worse you know like at the the end of the day as much you want to talk about that enum that we just saw somehow it's still wors okay Beast stop with your C it's not C it's PHP I love today okay birthday boy bisco by the way YouTube you better wish bisco happy birthday in the comments okay I expect to see it I expect at least a hundred happy birthdays when this video goes out first class enums is you can now use them as typ hints so if a method is expected an enum you can hint that enum class and that way PHP will validate that the incoming argument is that enum all right here we go we're going to run through a bunch what does that mean validate uh I'm curious what that means if you just pass in any old in will it say hey I can't validate it or will it throw an exception if it doesn't match does it have runtime implications a little bit more curious about that last one okay so this is the big one this is the big one types types and more types ways you can add types to PHP first you can have typed arguments in this we say A and B must both be integers this is a scalar type hint You could also type hint classes or enums like we showed earlier you can have return types in this case we're saying it must also return an integer that makes enough sense if you're adding two integers together it should return an integer but not all numbers are integers some numbers are floats so you can also have Union types you can say int or float rock on rock on on that one I'm liking that I'm liking that a lot and it can return an INT or a float if you wanted to add more than two numbers together and you have a Vari adic function you can also use types for that no problem let's move on to a class here we're saying that the argument input must be of type Fu or bar this is the union type that we just talked about but you can also by the way I'm much more I like Types on this side as opposed to the other side call me crazy but I like to read the type before I read the variable name as opposed to reading the variable name followed by the type okay so you know like rust go and typescript all have variables on that side whereas like C you know that's kind of what I grew up on was like C and Java you know it's it's on the other side for me I've just always liked it i' there's some argument for it right that's all yeah yeah you're not crazy it CPP shill maybe uh type left uh stick in my brain yeah it does are you crazy called it come on pick you know it's just just just feels right you know what I mean uh you know and I also think that int array is better than an array of int you know I I I just don't I you know that's one thing about go that always kind of irks me a little bit but you know the fact that go compil super super fast I don't give a I don't give a damn you know what I mean if you can if you can compile an entire project in zero seconds you you know what tell me how you define your ins I I'm just fine with that you tell me and I don't care like right like I have various levels of what I care about and that ain't it uh Hey thank you King I'll say thank you in a second we're kind of you know we're we're like in the middle of something okay you know what I mean you know what I mean dog okay it's BEAST's birthday so I want you to say happy birthday to him have an intersection type where you say that the argument input must be of type Fu and bar which is really helpful when you're trying to ensure that an argument adheres to more than one interface but you don't care what the type of object is as long as it aderes to food and bar you can do whatever you need to do you want to get even crazier if you want to ensure that input is Fu and bar or it's nullable you can have a dis Jun normal form type and I had to he's about to say I had to go look up that but a disjunctive normal form type that literally sounds like a disease you would be classified with with your doctor um it looks like you have disjunctive normal form type learn those words for this specific video you can have Fu and bar or allow it to be null let's by the way pick right now is like actually it has pick I Can Feel It Coming pick I know what you look at this uh that's something that will make your uh your balls fall I thought you going to give me some insightful comment pick I actually thought I was going to get an insightful comment instead I got this is g to make your balls fall so why you know this the benefit of doing things live you know what I mean look at another example we've been typing arguments but you can also have typed properties so if you look at this class see that the public title property is of type string and the public date property is of type date time now this is a little repetitive isn't it we've got the two proper we've got the two arguments in the Constructor and then in the Constructor we have to set the class level properties I totally forgot that you have to do two underlines for construct is that was that always true was this always true I just I I honestly can't remember it it's shocking that I could do something for 80 hours a week for multiple years and forget it this is a little verbose this is how we used to have to do it until the PHP Gods introduced Constructor property promotion and now you can put the visibility in your Constructor signature you can say public string title and it will end up as a public property on your class this I actually do like that that t typescript also has this I'm not sure if that's a JavaScript thing or just a typescript thing but I've always liked I've always liked this I think this is very very good I don't want to have to specify things twice always been been a big fan uh C the C is called Constructor promotion I don't love that you end up with an empty Constructor body but I do love that it reduces all of that boiler plate if you want to Mark a property as read only meaning that it can only be initialized once and then never changed there's a keyword for that you can say that a property is read only and you can do that in the Constructor as well if your entire class is read only you can mark the class as readon instead of marking each individual property as only a lot of stuff has changed if you have by the way that actually is like these type of changes also allow the just in time compilation stuff to be much better right you can do a lot more with a language when you have more hints the more things you have the faster you can make it right the less you know about a language the less you can really do you have to like that's why in JavaScript if you ever look at the memory of any uh piece of JavaScript what you'll see is that there's all these hidden pieces of memory and they're like 30k 50k 10K Associated effectively with every single function because every single function has a huge amount of assumptions being calculated and kept track of such that it can optimize it at some point right and optimization is a function of length of your of your function which is also bizarre right so as your function gets longer the more runs it has to take the more memory it takes to actually optimize it the more things it has to keep track of it's very very uh it's very interesting and so PHP with inside like typing and all that I think that you can do a lot more cool stuff with how fast it runs by simply knowing this information I love it paying attention you might think PHP is dead but alas it is not dead talk about speed every time I make a video people are like yeah PHP is so slow PHP between like 5.6 and seven experienced a 400% performance increase and then I think another 20% between seven and eight I heard you're supposed to talk to a doctor if you exceed 400% is that still true or or is that different now or you can go longer than 400% giggity giggity long as you say that is not as slow as you remember so if you need something like 50,000 requests per second you should probably still you should probably still not use PHP for that but look at me listen to me when have you personally needed 50,000 requests a second how many users do you have so that was so based that was like the most base take of all time right there that was so good that was so good dude just just get wrecked just get wrecked HP is fast enough it is fast enough for most of your use cases and if you need a specialized use case use a specialized language but the PHP of your is not the same as the PHP of today it is much much faster it is much much better and it is not dead see you I really liked some of the way the ways he said things I really like that he called it the PHP of your that was beautiful by the way go subscribe to Aaron Francis what a great guy not only is he a great guy great guy when I met him in in IRL but also nice guy on Twitter always super positive sometimes I think he thinks that I'm a little bit of a goober very nice guy go give him a follow good guy I like him um PHP plus HTM X stream I'm gonna be doing golang because I'm cool uh you know I'm I'm actually cool but I could imagine that if I wasn't cool I would consider PHP sorry Aaron for that that last part uh but but Melky I get to do go to okay you can't go back to rust I don't want to go back to rust right now okay okay I did two and a half years of rust and I use rust like fulltime now or part-time and sometimes you need a break from what you're doing okay I don't want to be in the rust world anymore I want off that wild ride of rust okay o camel then but the problem with o camel is nobody knows what's happening when you show somebody o camel no matter how many times you hear in chat it's actually more intuitive nobody thinks that okay nobody thinks functional programming more intuitive and all these people that tell you that just have just drank so much Kool-Aid they cannot see the forest for the trees at all the name is I could actually like PHP a j
Info
Channel: ThePrimeTime
Views: 248,763
Rating: undefined out of 5
Keywords: programming, computer, software, software engineer, software engineering, program, development, developing, developer, developers, web design, web developer, web development, programmer humor, humor, memes, software memes, engineer, engineering, Regex, regexs, regexes, netflix, vscode, vscode engineer, vscode plugins, Lenovo, customer service
Id: WsnHWxO7Krw
Channel Id: undefined
Length: 25min 42sec (1542 seconds)
Published: Wed Aug 23 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.