Introduction to PHP

PHP is an incredibly popular programming language.

Statistics say it’s used by 80% of all websites. It’s the language used by WordPress, the widely used content management system for websites.

And it powers a lot of different frameworks that make Web Development easier, like Laravel. Speaking of Laravel, that might be the one reason to learn PHP these days.

PHP is a very polarizing language. Some people love it, some people hate it. If we move one step above the emotions and we look at the language as a tool, PHP has a lot to offer.

Sure it’s not perfect. But let me tell you no language is perfect.

In this new series I’m going to help you learn PHP.

I’ll explain modern PHP, version 8+.

PHP has evolved a lot in the last few years and if the last time you tried it was PHP 5 or even PHP 4, you’d be surprised at all the good things that PHP now offers.

Let’s go!

PHP is a programming language mostly used to create Web Applications.

As a language, it had a humble beginning. It was first created in 1994 by Rasmus Lerdorf to create his personal website. He didn’t know at the time it would eventually become one of the most popular programming languages in the world. It became popular later on, in 1997/8, and exploded in the 2000s when PHP 4 landed.

PHP can be used to add little interactivity to an HTML page.

Or it can be used as a Web Application engine that creates HTML pages dynamically and sends them to the browser.

It can scale to millions of page views.

Did you know Facebook is powered by PHP? Ever heard of Wikipedia? Slack? Etsy?

Let’s get into some technical jargon.

Programming languages are divided into groups depending on their characteristics. For example interpreted/compiled, strongly/loosely typed, dynamically/statically typed.

PHP is often called a “scripting language” and it’s an interpreted language. If you’ve used compiled languages like C or Go or Swift, the main difference is that you don’t need to compile a PHP program before you run it.

Those languages are compiled and the compiler generates an executable program that you then run. It’s a 2-steps process.

The PHP interpreter is responsible for interpreting the instructions written in a PHP program when it’s executed. It’s just one step. You tell the interpreter to run the program. A completely different workflow.

PHP is a dynamically typed language. The types of variables are checked at runtime, rather than before the code is executed as it happens for statically typed languages (which also happen to be compiled, the two characteristics often go hand in hand).

PHP is also loosely (weakly) typed. Compared to strongly typed languages like Swift, Go, C or Java, you don’t need to declare the types of your variables.

Being interpreted and loosely/dynamically typed will make bugs harder to find before they happen at runtime. Often the compiled can be a great help to anticipate possible problems. But on the other hand, an interpreted language has more flexibility.

Fun fact: PHP is written, internally, in C, a compiled and statically typed language.

In its nature, PHP is similar to JavaScript, another dynamically typed, loosely typed and interpreted language.

PHP supports object-oriented programming, and also functional programming. You can use it as you prefer.

In the next few weeks we’ll explore all the important concepts of PHP.

Stay tuned.

Download my free PHP Handbook!