We are starting a new course, and this time it’s the turn of one of the “great classics” of the web. We are going to talk about PHP.
You have probably heard a thousand times that “PHP is dead”. It’s a recurring meme in the development world. But, if we look at the data, the reality is very different.
Today, PHP continues to power a huge part of the web, from small blogs to content management applications and systems with millions of users.
The PHP we are going to learn here is not the PHP of 15 years ago. We will focus on supported 8.x versions, a fast language with type declarations and object orientation.
This course assumes you already have basic knowledge of HTML and some general programming logic.
What is PHP?
PHP (recursive acronym for PHP: Hypertext Preprocessor) is an open-source, interpreted programming language specifically designed for backend web development.
Unlike JavaScript, which (traditionally) runs in the client’s browser, PHP code runs on the server.
This means that when a user visits your website, the server processes the PHP code, performs the necessary operations (such as querying a database), generates the resulting HTML, and sends it to the browser.
The end user never sees the PHP code; they only receive the HTML, CSS, and JS that the server has “manufactured” for them.
A Brief Bit of History (Very Brief)
To understand why PHP is the way it is, we need to look back for a moment.
PHP was born in 1994 by Rasmus Lerdorf. At first, it wasn’t even intended to be a complete programming language. Rasmus created a series of C scripts to track visits to his online resume. He called it “Personal Home Page Tools” (hence the original name).
The community started asking for more features, and the language evolved organically (and sometimes a bit chaotically).
- PHP 3 and 4: Popularized the language, but it was still very procedural and somewhat inconsistent.
- PHP 5: Introduced a solid Object-Oriented Programming (OOP) model, which enabled the birth of professional frameworks.
- PHP 7: Was a quantum leap in performance. Suddenly, applications flew.
- PHP 8: Incorporated JIT (Just In Time), attributes, and new improvements to the type system, while continuing to expand the language syntax with each version.
How Does the Client-Server Cycle Work?
Understanding this cycle is important. When we work with PHP, we are on the backend side.
Request: The user’s browser requests a page (e.g., tienda.php).
Processing: The web server (like Apache or Nginx) detects it’s a PHP file and passes it to the PHP interpreter.
Execution:
- PHP reads the file from top to bottom.
- If there are database queries (MySQL), it executes them and retrieves the data.
- If there is conditional logic, it decides what to display.
Response: PHP “outputs” a purely HTML document which is sent back to the browser.
Why Use PHP?
With so many options like Node.js, Python, or Go, why should we choose PHP? Here are my technical reasons:
The ecosystem is brutal
PHP has Composer, one of the best dependency managers out there. Through Packagist, you have access to thousands of tested and maintained libraries to do practically anything: from generating PDFs to connecting with AI APIs.
Top-tier Frameworks
If you want to work professionally, you won’t be writing “pure PHP” all day. You’ll use frameworks like Laravel or Symfony. These frameworks facilitate best practices, design patterns like MVC and dependency injection, and offer ready-to-configure security tools.
The Barrier to Entry and Deployment
Deploying a PHP application is ridiculously easy. You don’t need to configure ports, daemons, or complex background processes if you don’t want to. Any €2/month shared hosting supports PHP.
For prototyping and launching projects quickly, PHP is unbeatable.
Modern Typing and Performance
The big change in PHP 8 is its type system. Now we can write robust code:
// Modern PHP
function calcularTotal(float $price, int $quantity): float {
return $price * $quantity;
}If you try to pass a string to that function, PHP will warn you. This drastically reduces bugs in large applications.
What PHP is NOT (Myths to Debunk)
- “PHP is insecure”: False. Badly written code is insecure in any language. If you use prepared statements (PDO) and follow best practices, PHP is as secure as Java or C#.
- “PHP is for cheap websites”: False. Facebook, Slack, and Wikipedia scale to millions of users using PHP (or its variants).
- “It’s spaghetti code”: Only if you want it to be. Nowadays, the standard is to use Clean Architecture, Classes, Interfaces, and Unit Tests.