We’re going to go through this programming language really fast, because I assume that you already know at least one other programming language, perhaps Python. And so, this is not so much about how to program, but this is the quirks that are PHP. So it kind of helps to put PHP in a bit of a historical perspective with the various languages over time.
The ancestors of PHP Language and history behind it.
And so this is my little chalk talk on PHP. And so long, long, long ago in the 1940s and the 1950s, we programmed in machine language and assembly language, where we actually understood the real instructions of the computer. And then the idea was more people could write code if we would have higher level languages.
And so in 1955 we had FORTRAN, which is my first language, and still another language. And then we sort of had languages that end users used because those were the folks that needed to get work done. But the C language in 1972, which came out along with the Unix operating system, was this first language that was approachable enough, it’s a pretty challenging language, I’d like to teach a class on it someday. It was approachable enough, but it was also performant.
And then perl came out, and perl really influenced a lot of things. And Python and PHP are kind of like scripting, interpreted languages, not thought of as fancy, super computer languages, or languages for super cool software developers. And so, PHP is an interesting creature, in that sort of perl is written in C, Python is written in C, PHP is written in C.
PHP of those three languages took a lot of syntactic inspiration from perl. But it also took syntactic inspiration I mean from C. But it also took syntactic inspiration from perl. And so this kinda leaves PHP, which is the language we’re talking about today. And an interesting, a schizophrenic kind of a situation. And we’ll see that, and I’ll try to point out where PHP is schizophrenic, a little bit. So the syntax is inspired by C.
We see semicolons. We see curly braces. We see no significant white space. Although, we always do it. But also perl is a big influence on it as well. So things like the dollar signs to start variable names, and the heavy dependence on the notion of associative arrays.
PHP in last few years.
Now in the last six, seven years, PHP has been influenced increasingly by languages like Python, Ruby on Rails, and Java, just to kinda keep up things like the object orient patterns, etcetera, are more recent additions to PHP. And so they really take off of other languages, not sort of perl and C, but the base, if you go back to like PHP 4, it’s felt very C like with perl weirdness.And we’re not talking about the more advanced stuff in this lecture, we’re talking about just the basics of it.
So, if you watch my interview with Erasmus Lierdorf, the creator of PHP, you will realize that PHP is a productivity tool. PHP is not a computer science exercise to make the most glorious and beautiful programming language. It is a language that makes you productive. And with that comes responsibility. With great power comes great responsibility. And so they didn’t worry about flexibility and syntax. If you wanted to do something, you knew what you were doing.
So PHP is not a language that’s trying to coddle you in anyway. If you type something and it works, you are kinda responsible for that. And so there’s lots of silent errors, silent auto conversions etc. And I’ll try to call those out in the rest of this lecture so you just understand that it does things, and it’s purposeful. It’s purposeful because it assumes that you’re a moderately good programmer, and when you type x+y, you know what x is. And you know what y is. And you know why you’re trying to add them together. And so it really is a much more forgiving language. But you can get yourself in trouble.
If you make a mistake, you won’t always catch it. And so a language like Java, which is a really good language for really large programs, because it has all this rigor and enforcement. And you make the tiniest mistake, and it checks a million lines of code, and catches the 14 places that that mistake was caused. That doesn’t happen in PHP. If you make a mistake, you are responsible for it. So here is basically how PHP works. PHP is designed to be embedded in a web page. And there is this special tag, and other languages have used this less than question mark tag, which is switch into a programming language.
So originally it was called Server Side Includes, where you would say, here’s some HTML, just like any old HTML. And let’s run some code on the server, less than, question mark PHP. So run this on the server. And so this is like a little program running. And the output of this program is what replaces this. So when the program code runs on the server while this page is being rendered, it’s like write this out, write this out, run this code. And then write whatever comes out in the webpage.
So what we see in the webpage is the HTML plus the output of this thing. And so that’s how this works. And so if you take a look, if you take a look at the source code to this HTML page, you will see that it just intersperses it, and you can’t tell the difference between the text that came from the original HTML in this file, and the PHP code, and so the output is just merged. This output is just merged into the PHP, I mean, into the HTML. And the browser, when it reads this page, didn’t know what came from HTML, and what came from PHP.
I say that Python is the right language to do data analysis, and computer maintenance tasks on your computer etc, etc. But people do it in PHP. So if you ever see it, don’t be super surprised. And maintenance tasks, sometimes people will write PHP scripts to connect to the database, and run a long running thing from the command line. Because you can’t run a long running process as part of a request response cycle. Otherwise, your web server will time out.