Check out a free preview of the full PHP Basics course
The "PHP Language Features" Lesson is part of the full, PHP Basics course featured in this preview video. Here's what you'd learn in this lesson:
Maximiliano walks through some of the language features of PHP. Since PHP is an interpreted language, the source code is not compiled but shipped directly to the server.
Transcript from the "PHP Language Features" Lesson
[00:00:00]
>> Maximiliano Firtman: So I'm talking about language types to understand where PHP is actually located. So we have compiled languages where you write code in those languages and you ship machine code. For example, C, C++, Go are languages in this part. We have languages where you write code in, for example, C-sharp, and you then ship bytecode.
[00:00:29]
So you compile to an intermediate language, and then you ship bytecode, for example, Java. And then we have interpreted languages, or scripts Scripting languages, sometimes we say where we directly ship the source code. Where we deploy to the server or to the platform directly the source code, PHP belongs to this list, okay?
[00:00:54]
So with PHP, you will publish your source code directly to the server, okay? Like with JavaScript that we publish directly, the source code to the browser, okay? Things like that. Okay, so key features of PHP before actually going and writing some code. It's a very, very, but very flexible language.
[00:01:15]
We mentioned that a couple of times at this point. So it's platform, so the interpreter is available for Unix-based system, for Windows, for Linux, for Mac. There is an interpreter for Android, in case you want to do that. We mentioned that we have one in JavaScript now, so you can actually run it in the browser.
[00:01:34]
So we have interpreters of PHP everywhere. Also, it has a wide, probably one of the widest database support APIs available. So you can actually use any database. Of course, that's on a language you also have for the main providers, but there are some not so well-known databases out there.
[00:01:54]
Well, PHP has support for it. It's open source, we already mentioned that. It's multi-paradigm, this is what I said before. You wanna do OP, go ahead. You don't wanna repeat, you don't need to. So you can just write code like spaghetti code and it will work. It has a very rich standard library, rich in terms of the amount of functions that are available.
[00:02:18]
That's also one of the main criticisms are coming to that library, because it's actually a list of thousands of global functions that are not sometimes following the same naming guideline. As I mentioned before, is null, is set, we have one, we underscore, the other one doesn't have underscore, so it's kind of a rich.
[00:02:40]
A list of functions, you will always find a function you want, but sometimes you also have several ways to do the same thing with different paradigms. This is something that we don't see these days. It has session management built in that one of the great advantages of PHP.
[00:03:00]
And it's still a great advantage today compared with Node.js or Python when you're doing backend. So what is session management? It has some kind of a library built in, I mean, it's not magic, I will explain how it works. But when you visit a website, a PHP, you can store variables in the session, server side.
[00:03:24]
Then if the user continues navigating your website, you can get those variables on additional requests, on future requests, and automatically, it just works. Internally, it's creating cookies and to create a session ID and saving those variables service update. It has all that thing built in. So a web designer without branding comes where programming knowledge or skills can quickly do that.
[00:03:56]
So you fill your name in a form and you save that In the session and then you know the name of the user, you don't need a database, you don't need to do anything. You shall save something in the session and automatically that works because you know that HTTP, the protocol we're using on the web is stateless.
[00:04:16]
So on every new HTP request we are making it a new one. It doesn't have a relationship with the previous one. So from a service point of view, we don't know if this request is coming from the same user as five minutes ago, so I don't know. So we have to use a design pattern.
[00:04:34]
In fact, you hack that to know server side if it's the same user or not. Well, session management is built in PHP. And we can get from an idea to an app in a matter of minutes. When you already know PHP, I mean, when you are doing that, when you're using, I don't know, you want to use Express.js with Node.js, yeah, you need to create a server.
[00:04:56]
You need to install dependency, you need to do this and that. With PHP, you can just write three, four lines of code and yeah, we can discuss if we can scale that If it's secure, it doesn't matter, but we can get an MVP [LAUGH] really fast, okay? A minimal viable product.
[00:05:13]
Why did you learn PHP fundamentals now? Well, we already mentioned some parts, but the web is powered by PHP. So it's always a good skill to have in your resume to maintain legacy web apps. Because by the way, it's true, it's difficult to find a company these days, mostly in a startup that says, we are going to start a new AI company, and everything will be based in PHP.
[00:05:42]
Yeah, that's not actually the most common situation. Okay, for different reasons. It doesn't matter, but it's true that that's not the situation. So it will be more common to maintain web apps that were created in the past 25 years. Of course, if you use WordPress, Joomla, Drupal, you will need PHP to extend the basic behavior.
[00:06:05]
So it's good to know the language and understand the basics. Or if you're going to use one of the more popular web frameworks these days, Symfony, Laravel, or Code Igniter, there are more, okay? But those are more popular than Django or Java frameworks for the web, they're far more popular, okay?
[00:06:25]
Again, maybe in the long tail, maybe not in the mainstream, cool Silicon Valley companies, maybe in the long tail of the web, we have more usage of these frameworks.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops