PHP doesn't suck (anymore) with Aaron Francis === [00:00:00] Hi there and welcome to PodRocket, a web development podcast brought to you by LogRocket. LogRocket helps software teams improve user experience with session replay, error tracking, and product analytics. Try it for free at LogRocket. com today. My name is Paul and joined with us is Aaron Francis. He's a content creator as well as a developer educator over at PlanetSkill. Today we're talking about probably a hot button topic that a lot of folks are going to be interested in. We're going to be talking about why PHP doesn't suck anymore. Boy, we're excited to get into this one. Welcome to the show, Aaron. Hey, thanks for having me. I am here to preach the good news of PHP. So I'm excited to be here. So just a little background, Aaron gives quite the video repertoire on various topics and you are a PHP lover yourself and you talk about how great the language is. And one of the videos that you put out recently is quite literally titled PHP doesn't suck anymore. And you go over a bit of options about well, I don't want to call them options, but [00:01:00] features that haven't been available. So before we get into the nitty gritty and like maybe talk about some of these great new things, such as enums, very exciting. When did you start in PHP and why did it grab your attention? So I'm one of those kids that started when I was like 13. And I think the first book I picked up was like ASP. net unleashed. That was my first programming book. And I did ASP. net as a kid for a little bit, but then I'm. Quickly moved on to PHP because it was just easier to deploy. You could, every shared web host had PHP and I was like, all right, I'll guess I'll use this language. And that's 20 years ago now. And I just stuck with it. It wasn't really a very well considered choice back then. I was like, Oh, this is easy and I can make cool stuff. And honestly, it's been the same ever since this is easy and I can make cool stuff. And. So now here I am 20 years later.[00:02:00] What was one of the most fun projects, that you embarked on that really made you go, Hey, I can do this for real. This development thing. Cause you didn't start out as a developer, right? No, I actually, so I, did it for fun as a kid, and then I went to college and got my degree in accounting, and while that sounds like totally insane, accounting is basically programming, it's just problem solving and puzzles and stuff but with numbers, and then I got into the accounting world and was like, being an accountant is terrible. I went to work at, I went to work at a big four firm, which was a good firm, but it was like, this is an awful job. And so then I just bailed and went back to programming. And that was the first time I did it like professionally. And I think. What made me think that I could actually do it for real was I just kept it just kept my attention. And so I wanted to continually return to programming, [00:03:00] and it was one of those things where it was like, Well, you could play, you could maybe play a video game, or you could program. And I was like, I kinda wanna program. I just wanna build stuff. I wanna make stuff. And I think that's what was like, Ah, if I'm this interested in it, I could probably make a career out of it and it worked, fortunately. Fortunately for everybody. Cause now you're here to help educate others on this stuff as well. So if you see people learning PHP from your point of view, why do you think so many people get turned off by it? Initially, and before we get into any of the specifics of the language and the tools just from a bird's eye point of view, Yeah. From bird's eye point of view I think there's a lot, I think PHP has a lot of baggage, right? So when I picked it up, it was, I don't know, PHP 5. 0 or whatever. And I, the reason that I picked it up is because it was easy and that's the reason almost everyone picked it up. And so there [00:04:00] is, there's just a huge amount of really bad PHP that exists in the world. Both legacy. and beginners. And so one of the great things about PHP is it's very beginner friendly. One of the bad things about PHP is it's very beginner friendly. And so you have this huge, you have this huge population of beginners writing PHP. And I think that means that by volume, there's a lot of really bad PHP code and that perception has lingered on and The language itself is full of we'll say lovable quirks. You could call them flaws, but we'll say lovable quirks. And I think that has gotten a bad rap. And one of the reasons I made the video is because I think people haven't looked at PHP in 10 years, but honestly, there's a lot of legacy and there's a lot of bad PHP out there. But that's just a, that's just a volume problem. because I was going to say we have people on this web [00:05:00] development centric podcast that are, JavaScript's the star of the show every day, and there's no beating around the bush to say that JavaScript doesn't have baggage oh, my gosh, There's so much baggage of JavaScript. So there, it's interesting to look at what bad, like what baggage is different and why it caught on, a little bit more than PHP in the modern day and age. In the video, in your YouTube video where you talk about PHP doesn't suck anymore, you noted 5. 4. Like the paramount turning point, was that a do you think that offered in a new like cultural shift into how the language is used to maybe not make these beginner friendly mistakes? Is it trending in that direction? I think it's still really easy to bet to write bad PHP But I think it's still really easy to write bad anything frankly so the reason I picked 5. 4 is because that was maybe I think 11 years ago that 5. 4 came out and in 5. 4, they started to like the the velocity of changes and the [00:06:00] velocity of improvements really started to pick up. And I think one of the meta points that I was trying to make in that video is y'all, the PHP core team. It's working really hard and they're, like, continuing to adapt to this changing environment and this changing world. And my guess is that, I don't remember exactly when Basecamp and Rails and Ruby started to take off. But I think that was around 2007, maybe? 2006, 7, 8? Something like that? And I think PHP lost a lot of people to the Rails world, the Rails ecosystem back then. And so I think a lot of people in their minds have PHP pegged back in the early 2010s, late 2000s, right? And so one of the reasons I picked that era to go back to is it's long enough to go back to that most of these senior programmers in other languages They remember, like they remember PHP. Everyone has gone through a [00:07:00] PHP phase and they remember it. And so I wanted to call back to be like, hey, I bet you stopped using it back then. Well, look at all the neat stuff we have now. Awesome. And of these, if we're at this bird's eye view point right now, of the things that you think PHP does uniquely, or PHP does, really correct that kind of fosters ideas in either you or you've seen in other people in the way to develop what might some of those be that bring you back to the language continually. Yeah, honestly, the things that bring me back to the language have very little to do with the language itself, which is weird to say. The community and the culture of PHP is very much like a like a builder, hacker, maker culture. And that is, that's deep in my bones. I want to like, I want to build things. Like I really enjoy the craft programming. I actually do. But at the end of the day, I want to use that skill [00:08:00] to I don't know, build something. Like I want to make a SAS app or a tool or a cool open source package or something. Like I want to accomplish a thing. And I think that's always been one of the great strengths of the PHP community is that we're really trying to use it as a means to an end to build something. And so this community is very very resourceful and productivity focused and building focused. And that, that manifests itself in a few ways. We don't get into a whole lot of arguments internally in the community about things that may be minute or may not super matter because our community is I don't know, just do whatever you want. And that could be seen as a negative, where it's well, you're not respecting the craft of, software development and those we have those conversations, but honestly, it's Hey, what are you building? Oh, cool. What are you working on? Oh, cool. That's great. You building a, a side business, a SAS, are you working on something? And that's what keeps bringing me back is like the language is [00:09:00] totally good enough, but the community, in my opinion, is just simply unbeatable. Something about, is definitely to be said about opinions and the opinions that can be formed in a community. Are those opinions productive or not? That's another question. There's, there are a lot of opinions in the JavaScript ecosystem. Like we, we know about that. Well, you could have a whole podcast just on the opinions about React. Is it a library or is it a framework? Yes, could start a TV show. Yes. You would have, that's an infinite content glitch. If anyone out there is I don't know what to write about. Just react opinions and you'll be set for years to come. Yeah. If any of our listeners out there are making your stacks out in JavaScript, if you're making any big full stack apps, I just want to remind our listeners that the podcast that we're listening to right here is brought to you by LogRocket. And LogRocket is a framework that is aimed at helping [00:10:00] you solve bugs faster and spend less time digging through your console, digging through your developer tools so you can spend. More time building and more of your focus and energy building so you can use some of the new features that are coming out such as AI to look over your errors, surface different trends faster, and all sorts of other cool things like heat map. So head over to log rocket. com to try it for free today. Now, Aaron, I would love to take the next section of the podcast and kind of dive into the specifics that you were mentioning the video because I, for one, as somebody who doesn't spend a lot of time in PHP and seeing and only having worked with old PHP code in the back, like when I made my Raspberry Pi front end for my LED app. you go. See you're a PHP hacker maker at your core. I knew it was in there. There you go. Yeah. It actually came out in a hacker context, so. Yeah, folks were using PHP just to get it done. Just get the damn thing done. So, but there are a lot of things that you mentioned that I just [00:11:00] had no idea like could be a thing in PHP or there are things that I'm like, wait, PHP didn't have that. And now it has it. Okay. That's, that sounds really good. And one of the number one things I hinted at the beginning of the podcast was enums. So we didn't have enums before. Was that in 5. 4 or did I come Gosh. Now, if you're going to ask me which version they came in, I'm going to fail, but I know they weren't in 5. 4 because I know that they were quite a bit later. Surprisingly. So it used to be like in PHP, what we used to have to do is you would create a class that was like we'll call it blog post statuses or something, or just statuses. And then in your statuses class, you would have a bunch of class constants that was like archived, published draft in review. And so you within the class and so you hacked your way around the fact that first party enums weren't available and It was okay but now we've got like first party enums [00:12:00] and what that allows us to do is that allows us to like You can have a, an enum that's like archived, and if you want to put a backing value behind archived, so like in your code base, you want it to be nice and readable, archived, published, whatever. In your database, you want it to be compact and efficient and small, so you'd maybe do 0, or whatever. So now PHP in there, and with backed enums, you can have both of those things, and you can use a string as a backed enum, so you can like, Say, I actually want to store the word archived in the database. That's totally fine. So that's like very basic level, but then beyond that, now that enums are a first party citizen, it's like a first class object in PHP. You can have stuff like so you have your enum class, which is like blog statuses. You've got your four enums at the top, but then your enum class can be filled with methods. And so you can have a method. That's two friendly display or whatever and it receives [00:13:00] whatever that enum is and you can return a human readable string so now your enums have become a little bit stronger where it used to just be You know, the enum had a word and a value associated with it. Now it's this rich set of features where you can encapsulate I need to show this in the mobile app, or I need to show this in the front end, or I'm going to do my translations here. You can wrap all that up in a class. And then finally, everybody loves types, right? JavaScript community, they're like, Oh man, I got to have my types got to have type safety. If you don't have type safety, you're failing, right? It's Okay, well, whatever. Anyway, you can now type hint you can type hint in enum. And what that means is if you have a method that is expecting an enum, And that enum is, archived or published or whatever. You can, on the method signature, say that this incoming argument must be an enum of blog status type. And what that means is, it's not like checking to see if it's, value [00:14:00] 1, 2, 3. It's checking to see that you actually passed the enum value in, like the enum itself, and not like the backed value of 1, 2, 3. And so Now all those people that love type safety, of which I am barely one of, like I don't super care about it. But now you can type in your enums and be like, this expects a proper enum and I'm going to give you a proper enum. And so that's the deal on enums. Like we used to like with everything else, we would hack our way around it. And now we can, we can do it the proper way. Another feature that really caught my eye that felt super special to me as somebody that I mean, I'm sure this exists, apologies to other language lovers, if this is in your language and I'm saying that, but it just felt special to me, the sensitive attribute, like this is something that I can just throw around in my code and make sure the logger doesn't spit it out to the console, wild? Yeah, so I think I should have looked at, I should have written all these point releases [00:15:00] down, but like in 8. 0 or 8. 1, something like that we got the concept of attributes or like annotations to where you can mark you can mark a method as something and you can add these little basically like decorators to methods or attributes or whatever. And one of the ones that is built in is these, this sensitive parameter or sensitive argument, whatever it's called annotation. And what that does is that tells the language like, Hey, I'm about to log a user in, I'm going to pass in username and password to this to this function, and then I want you to do the bcrypt and compare the whatever, whatever, right? It is possible, because the user has submitted their password, it is possible that password could end up in your logs, and you really don't want that, right? And so now, at a language level, you can tell PHP, hey, this is a sensitive parameter, I need you to redact [00:16:00] this from every log, stack trace, whatever. And so that, at a language level, protects you from accidentally logging PII as long as you're annotating these attributes with sensitive parameter. And it's just that's the kind of thing where, that's the kind of thing where I look at it and I'm like, somebody that was building an application In the real world, looked at that and was like, we should add that to the language level. And that's the kind of stuff that I'm just super here for. Because that totally solves an actual problem that application developers have. And I love that. It feels like a melting pot. Really good ideas that you get from the PHP ecosystem. Going down the list of things he threw into the YouTube video, it's Whoa, I saw that in that language and I saw this one in that language and like this one had a lot of support over there. And it's just all here now, I know, a lot of the comments were like, Oh, so it's just becoming JavaScript. Oh, [00:17:00] so it's just becoming TypeScript. Oh, so it's just becoming C Sharp. And I tried to reply to most of them, and my response was like, Isn't it wonderful how languages can learn from each other? I think they thought they were dunking on me, which, it's YouTube, I don't, I don't really care. I don't take any of it personally. I think they were, they thought they were being clever, and my response is always trying to be good natured, and I was like, Sure, yeah. Totally. That's awesome. Isn't it great? We should be happy that's the case. Some of those JavaScript, TypeScript sort of things that really hail home to those language lovers out there. They feel like a great natural progression because there are some things that maybe were in classic PHP, like short array syntax, right? We can use brackets now. That's one of the things you just started the video off and it's wow, that really makes sense. It could definitely alert in a whole new crowd of spectators who are on the fence about it. They're not trying to like, Oh, wait, I this is more comfortable for me. I can just immediately get it. [00:18:00] I know what it's saying. What are some of the TypeScript, JavaScript, these sort of features, if you just want to give those a quick advert. Yeah, for sure. So we, as PHP, have started adding types basically everywhere. And so, PHP obviously has, first... First party classes and we've got enums and so you can type hint all of that So you can say on your method signature that like you must pass a user class To this function or to this method and so that's one place where you can start type hinting And so I find that really useful honestly if I'm passing around models of, a lot of times we use an active record style implementation in Laravel, the framework, which we should talk about, but if I'm passing around models, I like to know that the incoming argument is of type user or is of type blog post or whatever. So that would be type hinting on like a function or a method signature. You can also [00:19:00] type hint like, just scalar, just normal types like int, float, string, that sort of thing. You can do return types. And so you can say this method must return a int, float, user, whatever. On your classes, you can also type hint and say that like this attributes. This attribute on the class level must be a Boolean or an integer or whatever. And so those are a lot of the places you can start to add types. One of the things we cannot do natively is generics. And listen, I am not, I'm not much of a type head. Like I don't super care, but I understand that a lot of people do. And So we can't, at a language level, add generics yet, and so you could have some stuff that you can't really do in PHP that you could do in TypeScript, but we also have world class tooling that allows you to add that on top. So, I would say that if if we were to compare [00:20:00] JavaScript to PHP, PHP has way more types than JavaScript, right? But if we were to compare JavaScript to TypeScript, TypeScript has more, but TypeScript is like a whole nother language topper on top of JavaScript. And for our purposes, We've got tools like PhpStan and Salm, P S A L M, Salm. And those are static analysis tools, and those add even more type support, including generics and static analysis and runtime analysis and all kinds of stuff like that. So we do have additional tooling, but I was really focused on just the language level in that video. Gotcha. And let's, let's talk about it, Aaron. Why should we talk about Laravel? Oh my gosh, what a great question. You set me up perfectly. So we talked about the reasons I keep coming back to PHP and the community is a big one. The productivity of Laravel, in my opinion, is unmatched by [00:21:00] any modern web application stack. So, let's break that apart a little bit. If you're building a modern web application, you need a lot of things these days, right? You need you need a database layer, you need authentication, you need queued jobs, you need scheduled jobs, you need background jobs, you need to be able to send emails, you need all kinds of stuff to basically end up at the starting line, right? It used to be you could throw up a website and you get rich immediately. Nowadays, it's Oh, we got to build something. You got to build the real deal. And so Laravel is a it is a, it's a framework that is written in PHP and it brings you an unbelievable number of first party solutions. And I feel like I say, I'll go and preach the Laravel gospel and people will be like, JavaScript has that, JavaScript has Authentication you could [00:22:00] use, clerk or next auth or something. JavaScript has Queues you would just use I don't even know you just use this package and I think the big differentiator is with Laravel All of that stuff is built in to Laravel itself. And so what happens is, if it's not built in, you end up spending a lot of time inventing the connective tissue between, let's say, five or ten different packages, because you need your ORM to interact with your background job. package and you need your ORM to interact with your email package. And so what you do is you pull off these, all of these single packages. And not only do you, not only do you write all the connective tissue yourself, then you also have to deal with independent Upgrades yourself, right? So let's say your ORM moves to version four [00:23:00] on Tuesday. And then your email provider moves to version three on Wednesday. And you're like every day, there's a new opportunity for one of these major components of your application to be upgraded independently of every other. And so then you're scouring blog posts online of like. How do I get how do I get Prisma to work with next off? Oh, what version of Prisma? Well, I gotta go. So you're doing all of this work so that you have the air quote freedom of building your own framework. And I'm like. Listen, I don't want to do any of that. I don't want to do any of that. I want some individual single entity to have thought about what is required to build a SAS application. And I want that to be thought through from local development all the way to production and with millions of requests, like I want somebody to think through that whole life cycle and then I'll come in on top and write the business logic that I need. And I feel like that's where Laravel has really [00:24:00] succeeded is they've got several full time salaried developers simply working on open source. And so. It's probably most analogous to Rails, except Rails doesn't have the, the Rails team has base camp and they have other things going on. The Laravel team is just focused on Laravel and making the lives of Laravel developers easier. And that's that whole I just can't, I can't move any faster. Like I can't pick any other stack and move faster. And then for the JavaScript friends. You can use view or react on your front end. Like there, there are first party solutions to like, how do we use, how do we use Laravel with react? So one of the other things I like is Laravel hasn't invented like a JavaScript framework that's Laravel specific. It concerns itself with. What is the best back end solution in the world and how do we integrate with the best front end solutions in the world? And so we've got Vue, React, and then we have a Hotwire, something that's similar to [00:25:00] Hotwire called Livewire Which is basically an HTML over the wire thing which would be similar to HTMX if any of your listeners are familiar with that So that's my pitch. That is what I believe and I'm sticking to it That sort of thing becomes increasingly pertinent, as you said, like the amount of services become more And more typical developer needs to learn way more to boot up a web app today than they did 10 years ago. So And it's like the I forget what the math term is, but it's like for every node, you add to the network, the it increases in complexity a certain amount. And that's how it is when you build your own framework out of off the shelf packages. It's like everything interacts with everything else. And so once you have, 20 core packages interacting with 20 other 19 other core packages, it's like, Oh, that complexity is through the roof. if somebody like my let's say like myself has played with PHP, they've [00:26:00] written a few functions, and they're like, Okay, I want to give this a modern and earnest try. What would you say is a great way to get started? Is it making a Hello World web app? Do you suggest making a data processing thing just for the back end to run through a file? That is an interesting question. I would I'll give you a couple of answers. There is first if you just want to learn, there's a site called laracasts. com and it's a great video tutorial website and there's a whole free series on modern PHP. and on like up and running with Laravel 10, which is the latest version. So if you just want to like idly look and see what's going on, those would be good series to watch. Might surprise you how like neat some of it is. If you want to build something, I would maybe if you want to build a SAS, I would pull down one of the Laravel starter kits that gives you Gives you like a SAS skeleton all built out already. And you can start to poke around [00:27:00] with that. And that's neat because that will show you like that comes set up with team support and sending emails and a lot of stuff that's Oh, so that's how I would do this in PHP. If you wanted to build if you wanted to build like a fun CLI tool that, Took a CSV from your bank and like actually made it useful or something like that, which I feel like is a lot of what, these weekend hack projects are. It's I'm going to take some set of data that is terrible and I'm going to make it useful. You could pull down, you could pull down just regular Laravel for that, or you could pull down something called Laravel zero, which is really focused on CLI tools. And that would be, depending on what you want to do, those would be some options. Awesome. Well, those are two great ways for people to get started. If they want to look in the PHP ecosystem a little bit more Aaron, if There is one of your favorite niche features. I don't want to, I don't want to say what's like the best feature. Cause that's arguable and everybody has different use cases, but like the one [00:28:00] that wowed you the most, like I thought the sensitive attribute was pretty cool. What would you say that is for you right now in modern PHP? Let's see I think I'll give you, I'll give you two answers. Just in case one is terrible. I think the one that I enjoy the most is the ability to type hand arguments because that's about the level of typing that I want to do. That's a that's perfect for me. That is the sweet spot. I want to know that this incoming user. is a user class feel super great about that. One of the, so that's my first answer. If you hate that, here's my second answer. One of this is more philosophical. One of the things I put in that video was trailing commas and function calls and. A lot of people were like, dude, this is stupid. And it was a little bit, it was a little bit of, hey, we can have some fun as a treat, hey, like this is YouTube. It's I'm you know, I'm trying to be a little bit entertaining here. I think philosophically trailing commas and function calls. I look at [00:29:00] that and I'm like. Yeah, like way to go PHP team for just continuing to do the freaking work like what a dumb Stupid little thing but that makes developers lives a little bit easier because we have trailing commas everywhere else except in Function calls and y'all fixed it way to go. And so philosophically that makes me think Hey, PHP core team doing a lot of work without a lot of thanks, even if I don't care about trailing commas at all, what it's indicative of is somebody behind the scenes is just working and I really appreciate that. Do you feel like it's signifying that there's still strong investment and momentum in the language? Yes, I think so. Yep. I think there are, there's like a, there's like a PHP foundation. JetBrains has contributed a lot of money. Laravel itself has contributed a lot of money. And a lot of other companies and individuals have contributed money to keep. To keep PHP, the language going. And I just, I really like to see that [00:30:00] there's a whole there's a whole group. I think this may be really interesting about PHP. There's a whole framework interoperability group, and that's where this, like the heads of these frameworks, Taylor Otwell for Laravel and a bunch of other, I think Fabian from symphony and a bunch of other prominent members of the community have come together and decided like. Okay, y'all, we need to come up with this set of guidelines or this set of generally accepted principles that defines like how our frameworks are going to work together so that people can write packages that work with most frameworks. And so. They'll come together and decide on Okay, how should class autoloading work? How should what's the interface for writing a cache driver? And so now people can write packages and be like this package adheres to... PSR4, and that's oh, okay, within the PHP ecosystem, there's this, very public cabal of leaders that's hey, y'all, we're [00:31:00] all maybe competitors, we're all maybe friends, we're maybe enemies, but for the sake of PHP, Let's vote on some rules about like how these interfaces should look, how the date time immutable, what, like all of these things. And that pushes everyone together. And honestly, that's one thing I think JavaScript could do is have. The heads of all of these big libraries or packages, whatever you want to call them, come together and decide on, okay, we've got to, we've got to start setting some standards because it is, it's chaos out here, so that may separate the PHP community a little bit. Aaron, it's been a pleasure talking to you, reigniting the hype about PHP. We are running up on time. So I would love to broadcast to listeners where they can find more from you. We already mentioned your YouTube, right? You have a lot of prominent content on there. Do you blog, do you write and do you post anywhere else? Yeah, I do. So I have a personal site at Aaron Francis. com. It needs a little [00:32:00] love. Most of my energy these days is spent on video on my personal YouTube and video on the PlanetScale YouTube. So on the PlanetScale YouTube account, I talk about my sequel. So I'm like, I'm firmly guy from the early 2000s, PHP and MySQL baby. And so on, on the PlanetScale channel, I talk about modern MySQL. And then on the PlanetScale blog is where I do a lot of my writing about MySQL tips and tricks. And I did a full eight hour course on everything and, need to know about MySQL for PlanetScale. So that's most of where my content lives. Awesome. Well, Aaron, it was a pleasure. Like I said, and thanks for your time coming on. Yeah. Thanks Paul.