Skip to main content

almost 5 years ago Syntax Podcast

Hasty Treat - Spicy Takeout - PHP Is Good and We’re Just Re-Creating It

Wes Bos

Wes Bos Host

Scott Tolinski

Scott Tolinski Host

Topic 0 08:56

PHP has massive standard library that JS is catching up to

Wes Bos

Is it just words just all mashed together? Like, I'm looking at the image API right now, and there's image color extract Alpha. It's all lowercase, all one word, and there's not a whole lot of consistency

Wes Bos

is sort of the opposite of JavaScript in that there are bindings for absolutely everything, and It's pretty exhaustive when they go into now JavaScript, we're starting to see, like, things like the temporal API and a whole bunch of new method APIs, and We're starting to see JavaScript standard lib just grow and grow and grow in size where you don't necessarily have to reach for With FreshBooks.

Wes Bos

a it was really weird, but, like, a buddy of mine, we're in the hot tub, and it Just turned out the guy who did the talk was in the hot tub as well, and people are like, woah, rough rough talk. And he's like, yeah. Like, Facebook loves PHP, so this just makes So much sense for us. And and here we are, like, 10 years later, everyone's By default, it's hot reloaded and serverless. Mhmm. So the way that PHP works is this Invocation

Wes Bos

Next one, massive standard lib. So PSP, almost comically large. They have a standard live for Segment. I don't know if we have a whole lot of spicy takeouts in us because Scott and I are not super opinionated. Yeah. We're pretty chill. Well, it's something that you're not necessarily super opinionated, but, Like, what's a spicy take that you got? Like, is there a is there a takeout that you could do? Well, I've been I've been getting pretty spicy on the React and Svelte stuff. That's true. I think we were trying to come up with names FreshBooks is The cloud accounting of the 1st code they wrote that was awful was PHP. Yeah. The early web was very much built on WordPress,

Wes Bos

then that script will run. And we're starting to see that now with a lot of these. Scott talked about this in SvelteKit. That's the way that it works is if you Is working as well. It doesn't have the scalability of serverless. You still have to think about scalability because you you can hit a a limit of running PHP scripts

Wes Bos

in that type of thing, which is pretty funny. I I always could see That is really frustrating. Yeah. You you would rely on your tools to know what those methods are that exist. Next one we have here is URL based routing. So by default, PHP, if you hit A script via the URL, on a specific box, but the whole idea of Or stimulus, Alpine JS. I saw Vue is also rolling out like a version of Vue where you can just use It's crazy. So We see that in Next. Js and a lot of these new frameworks where you just hit the URL, and the script that is at that URL

Scott Tolinski

Utility library for every single little thing that you need to do. Yeah. And that's, I think, a big plus. Yeah. The standard lib in JavaScript has been a little rough. Yeah. Naming conventions Of some of these are

Wes Bos

wanna have a dynamically generated what was it? A site map that you had? Mhmm. You just created a site map dot XML dot JS. And PHP land, you could very easily do the very same thing where you could dynamically generate any page via its URL.

Topic 1 00:26

Intro to Spicy Takeout episode

Scott Tolinski

spicy takeout, we're gonna be talking about How the web has kind of just come back around to what we used to be doing with PHP

Scott Tolinski

Wes, badass boss.

Scott Tolinski

for what a segment like this could even be called.

Scott Tolinski

What we mean by that and my name is Scott Talinski. I'm a developer from Denver, Colorado. And with me, as always, is the spicy

Wes Bos

Spicy takeout. I was just, like, kinda, like, writing notes for this one. I was like, this would be a funny Server render component, but then also rerender that sucker So PHP JavaScript sprinkles, turbo links. So that sorta that's the, like, PHP developers answer to a lot of this stuff is you can server render it and then pick it up in the browser or with things like Turbolinks

Scott Tolinski

CSF. Welcome to Syntax.

Scott Tolinski

and how we're just recreating most of it in JavaScript and

Topic 2 14:37

Why do people hate PHP and not use it nowadays?

Wes Bos

hate PHP,

Wes Bos

and why are Scott and I not using PHP? Why do we still use JavaScript after hit a URL with serverless,

Wes Bos

but I'm sure you might have some different insight. Yeah. I I think I agree with you there that It's a a combination

Wes Bos

PHP 7, those things are not as an issue anymore, and I think there's still a lot of people saying, yeah. I haven't touched it in A lot of these things that were had major security vulnerabilities pop up So sharing code between front end and back end, not having a context switch. Like, at the end of the day, you will have to write JavaScript for your application because, honestly, that's all you got. That's all you got. Sorry about that, but you can't run PHP in the browser. So if that's the case, then 1 single language to rule them all, being able to share dependencies from the back end to the front end. Honestly, the ability to share So I'm not a PHP dev myself. I do sling it every now and then, but I am a big fan of it, and I'll I'll attempt to explain why in this This episode.

Scott Tolinski

Saying all of these things to how amazing PHP is, why are we still going on in JavaScript? So what do you think? Why do people hate PHP Sky? You know, that's a Difficult question to answer because the answer really could be for a lot of reasons. People could hate PHP because they've heard somebody on Twitter say that they hate PHP. They could hate PHP because they wrote something in it, tried to modify a WordPress template, everything about it and know all of its quirks and features that are no fun to work in sometimes. I did I mean, it could be any any number of reason why you would hate PHP. I don't I don't hate anything. I don't really hate PHP, but, yeah, People probably just hate it because of a bad experience that they've had with it at some point in their career. And whether that is modern PHP or not, You know, it could be any of those reasons, In this

Wes Bos

PHP, BB.

Wes Bos

8 years, but

Topic 3 00:00

Transcript

Announcer

soft skill, web development, the hastiest, the craziest, the tastiest TS, web development treats coming in hot. Here is Wes, Barracuda,

Announcer

Tolinski.

Announcer

Open wide dev fans. Get ready to stuff your face with JavaScript, CSS, node modules, barbecue tips, get workflows, breakdancing,

Announcer

Monday. Monday. Monday.

Announcer

Boss, and Scott, El Toro Loco,

Topic 4 19:58

Final thoughts on PHP and its influence on JS

Scott Tolinski

for a full archive of all of our shows, and don't forget to subscribe in your CAS player, or drop a review if you like this show.

Scott Tolinski

Was there gonna be their big thing for using Hotwire? Like, shouldn't hate perform better? I haven't used it in a little while. Maybe that's a thing, but, like, hate was never super performant for me. And so maybe that kinda turned me off of the idea of Hotwire, and that could be just, like, straight up ignorance speaking. So if you wanna correct me, come at me. But I always felt like This is kind of a weird product to promote this new thing to do on because it it wasn't exactly like, you know, this is the fastest project I've ever used in my entire life or something. It always felt kinda slow, and I granted emails

Scott Tolinski

Head on over to syntax.fm access layer on top of that, but totally doable because the whole thing is server rendered. You don't necessarily have to worry about auth and all that. You can just run it. Yeah. You can run it on the server. There is something very nice about having To worry about 1 environment rather than the client and the server. Like, when you suddenly have to, like, this all this stuff has to run on the client and the server, you kinda inherently hit some Issues, whether that is security concerned about having access to that DB, whatever,

Scott Tolinski

was like or, hey, the emails.

Wes Bos

And the the ideas behind what they're doing much more than actually having to switch my email over. Yes. It kinda felt like, hey. What if what if you used a Google inbox but Had to have an entirely new email for it. I was like, yeah. I don't know about that. Yeah. Alright. That's it for today. Thanks for tuning in. If you have any Spicy takes that you think we should maybe try to cover? Tweet us at syntax f m, and, we'll see what we can do for you. Zig. Peace. Peace.

Topic 5 18:02

Why use JS over PHP nowadays despite PHP's merits?

Wes Bos

the server generated HTML, So people are starting to swing back the other way, Which is good. And that not everything needs to be client rendered. Yeah. Absolutely. What else do we got here? Get and post are just available. If you want your get and post input React is starting to roll out server rendered components. SvelteKit land has you can surf or render literally anything you want.

Scott Tolinski

but we have physical never really got super into it and had a hard time. Or they could hate PHP because they are a PHP master, and they understand And I remember never necessarily and you get the error log and network request and all that stuff that you use in your own development work environment.

Scott Tolinski

Swap out segments of your page really easily. You can get page transitions and animations, those types of things. We share types between the server and client, And then, I mean, I guess, some of that even comes from our API being in GraphQL, was really great. Like and hey.com

Wes Bos

The view bindings

Wes Bos

in your HTML Mhmm. And it will very much like Angular was in the in the early days. So there's there's a whole section of that as well. It just I just need to know that everyone's app is different, and there's a lot of different use cases for it. So that's my thoughts on PHP.

Wes Bos

That's something we haven't touched on, and it's

Topic 6 01:23

Mixing templates & logic frowned upon but makes sense

Scott Tolinski

Forward slash syntax, and you'll get 14 days for free. Again, this is one of those services you'll at least wanna go to their user dashboard and watch their little Their introduction, check out their home page. It's pretty amazing to see in action. Okay.

Wes Bos

and second 1 is LogRocket.

Wes Bos

syntax. Make Sure you use syntax in the how did you hear about us section. Thank you, FreshBooks, for sponsoring. This episode is also sponsored by LogRocket, spin up that function, Run the code and then spin down. That's exactly how PHP has has always worked, and there is no there's no starting a server or restarting it. And That's why I say it's hot reloading because, like, how do you test if something work with PHP? You refresh the page. And, or you refresh the script, and it will work. There's no starting and stopping of your servers, which is is kinda nifty.

Scott Tolinski

So let's talk about spicy spicy takeout.

Scott Tolinski

video that you can drag along and see exactly what happened, slightly different to break one of those rules, and it's, like, shocked Pikachu face, you know, just, like, like, what are you doing? And it's it's not always bad to experiment what those rules mean exactly. Next one we have here is every request has its own scope. So this, I'm gonna loop this 1 in with but it does it makes it considerably more complex.

Wes Bos

If you need some sort of cloud accounting solution, you can track hours and do expenses and all that stuff. Check it out. Freshbooks.comforward/ types files that we can share between the 2 of them, and that that's really huge. Totally. At the end of the day, I I think I just like the JavaScript syntax better myself. I'm better at it. Yeah. And that's Probably the thing at the other day is I am a much better JavaScript developer than I am a PHP developer, so there's something for that to be said. We have an entire show. If you go back to 267, for your small business, for your freelance, for someone who's just making a little bit of money on the side No matter how big or small you are, I've been with FreshBooks for over 10 years now, and it's great because you can log all your invoices. You can send them off To all of your sponsors, funny. FreshBooks sponsors this podcast. And how do I build FreshBooks? and they were sort of A bit of a mess to to work with. I think a lot of that has but there's still a lot of that in the world, but certainly there's a lot of awful JavaScript as well. Yeah. But a lot more modern

Scott Tolinski

And, honestly, when you brought Spicy takeout to the table today. I was pretty shocked because that was great. It's very good. Yeah. It's perfect. I was joking that it's Dim Mak, which is the death touch.

Scott Tolinski

which is the perfect place to see all of your errors and exceptions happen. In fact, we just launched a new UI for our site,

Scott Tolinski

replay

Scott Tolinski

and that's pretty stressful, let me tell you. But One of the neat things about launching a new UI on the client is really good. Client side rendering or in client side routing is great For me, I love client side routing, not having to Totally. Rerender the entire page. Every single attempt of going there, you can, you know, only

Wes Bos

solution it's awful. Right? And recently in JavaScript, we have back text, and you can interpolate a variable Or if you want instead of having to use in both cases, in JavaScript, you have to use a plus to concatenate strings. And in PHP land, you have to use a dot To concatenate strings, and those are a pain either way. Yep. All in one frameworks that do absolutely everything they do. Your templating, they do your Auth, they do your database access, all those type of things. Those have been a thing a long time. Back when I was doing it, it was CakePHP, CodeIgniter.

Scott Tolinski

is having a tool like LogRocket be there as a helping support net To make sure that you can debug any issues that you're going to have, because when you rewrite your entire UI, you're gonna have some issues. There's no way around that. So we actually have LogRocket on our site, and we use it just about every single day to make sure that our users are taken care of whenever they run into issues on the site. Now what is LogRocket? It is a error and exception handling service that allows you to see a video scrubbable

Scott Tolinski

Now, Wes, this is your baby here, so I want you to make sure that it's all represented correctly. So I'll let you kick this one off. Alright. So I've been having this

Scott Tolinski

When you have an error, let's say a user has a problem with your site, it creates a scrubbable video replay, you can Get a scrubbable dry code or, you know, don't repeat yourself. We need that stuff, right, that you hear just infinite loop. And then all of a sudden, somebody does something

Wes Bos

Alright. So we are sponsored by 2 awesome companies today. First 1 is FreshBooks, email's tough. But Yeah. Interesting. I only use hey, like, the 1st day, and then I Stopped using it after my name expired on it, and I wasn't super impressed with it, but it's kind of cool that they are what they're trying to do. I like the idea

Topic 7 12:29

Easy variable interpolation now possible in JS like PHP

Scott Tolinski

CodeIgniterium.

Topic 8 07:45

PHP is hot reloaded and serverless by default

Wes Bos

based, meaning that you write a script or you write a function, and then when somebody Need to hash out a m d five. You got it. Need to resize an image. You got it. The audio audio bindings.

Wes Bos

visits a URL where that function is called or that URL is Hit, then PHP starts. It invokes the script. It runs it, and it has its own scope for that specific function. There's no worrying about Sharing that between other people hitting that URL, and then when it's done, that script is done running, and it goes down. And that's kind of how serverless

Topic 9 11:23

Server-side rendering gaining popularity again

Wes Bos

Cool. Variable interpolation. You can just pop variables wherever you want. That's a big thing that we have in JavaScript land now, where in PHP, it's You have to use double quotes, and then you could just use dollar sign, the variable name.

Wes Bos

Variables to be available inside of a script, they are just available, and you don't have to pass them down from 8 levels low. You can get them wherever you want, and that we're starting See that in Next. Js Hooks land. What can I ask you what that looks like in SvelteKit land? How do you get access to those things? So you're getting access to the what is that actually? I don't even know what those are. If you were to submit a post request to your URL With, like, a form or if you were to have query params in a URL via those are Get. How would you access those in Sveltekit land? Oh, I mean, the the query params are just available inside of, like, a store that has all the location stuff in it. There you go. Yeah. Yeah. So it's avail like, a lot of that information about is available in in a given store or in the load function.

Topic 10 13:32

Direct database access from templates possible but risky

Wes Bos

DirectDB access. So it's not uncommon to see SQL statements directly inside of your templates, not amazing. That's one thing people have against PHP is that is it camel case? Does it have underscores?

Wes Bos

Which is something I believe we've talked about happening in JavaScript land at some point where you don't necessarily need a whole data layer. You could just reach into the database directly. Of course, that also has downsides, like SQL injections were extremely prevalent in PHP land. Most of those have now been cleaned up just because of the way. And, also, I should say, like, most apps are not directly You can go, like, fully typed in PHP 8, which are pretty good. A lot of people saying the inconsistent API naming, that Would definitely bug me as well Yep. Because they haven't tried Laravel yet. People the Laravel devs are, like, some of the coolest people I know, I think, because they're just like, Yeah. Whatever. I like PHP,

Wes Bos

So the question is, like, why do people

Topic 11 16:18

Using Laravel could be interesting to try nowadays

Scott Tolinski

Yeah. Right. Yeah. Yeah. I would be interested in building a site with Laravel just for fun to see, like, What does that feel like? What's that feel like in 2022

Topic 12 05:42

Every PHP request has own scope like serverless functions

Wes Bos

hated PHP for was separation of concerns, being like You can have your functions and all of your logic in the exact same file as your HTML that's rendered out. PHP is a templating language, but it also You could throw functions in there, and it's funny you sort of come back around, and you do that with JSX. You can put a function as well as render it out. And, Actually, I remember about 10 years ago now when I was at JSConf when React was announced, and everyone said, this is a joke. This is hilarious. Why would you miss mix all of your logic with your thing? And I remember SQL and data straight into their their views. They're using some sort of database PHP.

Scott Tolinski

being as because I I do remember

Scott Tolinski

templates and logic in some projects that I had worked in in PHP, but, like, It always felt kind of natural for me to keep things together like that. And at the time, like, I was using Meteor, which did a lot of that too. So and I don't know. It didn't feel like that crazy to me or that scary at the time, but I understood why people were freaking out because, like, in programming, we hear these things being, you know, Repeat it over and over again, whether that's always have

Wes Bos

googoo gaga over Hopefully, it wasn't too spicy for you, but I think that we've learned a lot from PHP. I have some extra spice to bring to this conversation. Yes. Let's have it. If Hotwire Beautiful. Yeah. Yeah. Absolutely. What else do we have here? Let me pull up a few more. A lot of people are saying the typing situation was sort of half baked, but with PHP 8, that's gonna be changed. So Okay. I was Just googling that.

Wes Bos

The first one is mixing template and logic. So one of the things people pretty much everything you can think of. So need to format a date. You got it.

Wes Bos

mixing your templating and your logic all in one file, because sometimes it just makes a lot of sense, and it's really easy to do that. Yeah. There was definitely quite a bit of kerfuffle about that.

URL based routing becoming popular again with JS frameworks

Scott Tolinski

Yeah. Yeah.

Scott Tolinski

Wow.

Wes Bos

will run.

Topic 14 04:06

PHP gets flack but has good features we now use in JS

Scott Tolinski

It's been a long time since I've last wrote a line of PHP. I think probably, like, This is just one of the most amazing tools that I've seen, and you can attach users and all sorts of information to it. You can see how many errors that you have at any given time. It is really super cool. See it by browsers, all sorts of stuff. So check it out at logrocket.com

Scott Tolinski

2013, maybe. 2014. Wow. It's been that long for me. It's because it that not that I haven't written WordPress sites or done that, but I've mostly been doing them in a headless context. So, like, I'm not touching the PHP really. I'm adding Advanced custom fields and whatever. I'm tweaking those things, and maybe I've thrown a debugger in here or there. But, man, I I I really have not Really gotten into PHP. Alright. So first, just laughing. One of the comments on this is I heard Nickelback 7 is pretty good, which is what people I say about PHP 7. Anyway, first point here I thought they were okay. I get it now. That's a joke. Okay.

Wes Bos

thread in our notion for probably over a year now. And every now and then, I come back to it, and I'm like, you know, modern web development or has had for years years, and PHP gets a lot of flack, so this is my spicy takeout in that I'm gonna attempt to explain why PHP is not so bad and they're not, like, trying to, like, convince you otherwise. They're just like, yeah. It's sweet. I enjoy it, And we run our app on it. It works well. So that always has looked good in my eyes, where the Laravel people are never obnoxious about using Laravel. They're just like, yeah. Sweet. Whatever.

Wes Bos

And why it is that we and specifically, Scott and I, JavaScript developers are we're taking the best parts of PHP really is. A lot of it is we are just recreating a lot of the features that PHP has And recreating them in JavaScript land. So we'll go through all of the points that I have here about that as well as, well, I send a tweet out. It says, why do people hate PHP? Starting to feel a little familiar. Yeah. I will say, like, there is also a bit of a Security concern there as well where you could potentially have something exposed that you don't want to have exposed. But And there's nuance here to all of this. So, like Totally. Totally. We're talking about the the broad strokes. What else? Server rendered. So server rendered everything is starting to become much more popular these days. What's the one in Ruby on Rails land that everyone's talking about? Hotwire? Hotwire.

Topic 15 16:39

PHP typing was half-baked but improving in PHP 8

Scott Tolinski

Yeah. We're building this wicked business. I'm efficient in it. I, make stuff in it. Yeah. You see that all the time. People there is a huge community out there of people making Awesome stuff with it. So I gotta have my I gotta have my client side JS, man. I gotta have that. Yeah. So there we go. Let's move to the next one. Why are we not using p if If we are so spicy on PHP being decent, like, why is JavaScript still better? I love how that's like a spicy take.

Wes Bos

There you go.

Wes Bos

What is the type situation in PHP? Yeah. I think you can type a lot of things in PHP, but, moving on to the future future? I asked on Twitter what people said, and we got some good answers. It's blocking by default, so you have to get into threads if you wanna be able to not have blocking with JavaScript just to sync a weight.

Topic 16 13:12

All-in-one frameworks like Laravel similar to past PHP frameworks

Wes Bos

Expression engine was of the paid version of that. Yeah. Last cup like, 6 years, probably, Laravel is the king of this. It's really nice to be able to do that, and then the Laravel community has a lot of really great frameworks and plug ins that you can use to And it's huge. Do things like Massive. Have a A GUI to edit your data. Yeah. Massive, massive community.

Share

Empowering developers for over 286197233843 milliseconds!