Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Browse all series

PHP For Beginners

We all start somewhere. For programming, this series is that first step. I've designed it specifically for newcomers to, not just PHP, but programming in general. Here, you'll learn the fundamentals of PHP - all the way down to defining basic variables and arrays.

Think of this series as a key stepping stone for your programming journey.

Progress

Series Info

Episodes
50
Run Time
10h 44m
Difficulty
Beginner
Last Updated
Oct 9, 2023
Version
PHP 8

Series Episodes

  1. The Fundamentals (11)
    1. How to Choose a Programming Language

      How exactly do you choose a first programming to learn? Why PHP, and not Ruby? And what about JavaScript or Python? How can you possibly be expected to make an educated decision at this early stage of your learning?
    2. Tools of the Trade

      Before we can dig in, we must first create the world, so to speak. To follow along with this series, you'll need to install a handful of essential tools. Let's go over them in this episode.
    3. Your First PHP Tag

      Our first order of business is to prepare some basic HTML, boot a PHP server, and view it in the browser.
    4. Variables

      Okay, let's move on and review basic concatenation and variables. The first time I learned about variables, my first thought was, "But why?". Let's talk about it!
    5. Conditionals and Booleans

      For this next episode, we'll build a quick webpage that displays a dynamic message based upon whether or not you've read a particular book. This will give us the opportunity to review both conditionals and booleans.
    6. Arrays

      At this point, you know how to create a variable for a primitive string or number. But what about situations when we want to declare a collection, or list of things? A list of usernames, or book titles, or tweets? In these situations, we can reach for arrays.
    7. Associative Arrays

      Let's stick with arrays just a little longer. In this episode, you'll learn the syntax for accessing individual items within an array. You'll also learn about associative arrays, which allow you to associate a key with each value.
    8. Functions and Filters

      Congratulations for making it this far! Let's take things a step further now and review functions. You can think of functions as the verbs of the programming world.
    9. Lambda Functions

      Buckle up, because we have a lot to cover in this episode! As part of our first code refactor, we'll discuss what lambda functions are, as well as when and why you might reach for them.
    10. Separate Logic From the Template

      Before we move on to the technical check-in for this chapter, let's set aside a bit of time to discuss code organization and why we might want to separate our PHP logic from the view, or HTML.
    11. Technical Check-in #1 (With Exam)

      Before we move on to section two, let's do a quick technical check-in to ensure that everything you've learned so far has been committed to memory. And don't forget to complete the quiz before continuing.
  2. Dynamic Web Applications (9)
    1. Page Links

      Welcome to section two! While section one focused entirely on the initial fundamentals of PHP, now, we'll move on and learn what it looks like to build a typical PHP application with a MySQL database.
    2. PHP Partials

      In the previous episode, we begrudgingly duplicated the same HTML for every PHP view. Let's fix that now by reaching for PHP partials.
    3. Superglobals and Current Page Styling

      Often, you'll need to apply styles or trigger certain logic based upon the current page. Luckily, we can use PHP's $_SERVER superglobal array to dynamically determine the current page.
    4. Make a PHP Router

      I think your PHP skills have now matured to the point that you're ready to build a custom PHP router from scratch. This will give us the chance to discuss code organization, response codes, and more.
    5. Create a MySQL Database

      We're now ready to begin interacting with a MySQL database. Before we write any PHP, let's first review how to connect to MySQL, and then create a database and table.
    6. PDO First Steps

      The next step on our journey is to figure out how to connect to MySQL from PHP and execute a simple SELECT query. We'll of course reach for PHP Data Objects, or PDO, to orchestrate this task securely.
    7. Extract a PHP Database Class

      Now that we understand the basic logic for initializing a PDO instance and executing a prepared query, let's clean things up a bit by extracting a dedicated Database class.
    8. Environments and Configuration Flexibility

      We have one glaring issue with our Database class right now. The connection values have been hard-coded. So what happens when we push the project to production, where the host and port are entirely different?
    9. SQL Injection Vulnerabilities Explained

      In this episode, we'll review some examples of SQL injection and discuss why it's so important that you always assume that, on the web, a person is guilty until proven innocent.
  3. Notes Mini-Project (8)
    1. Database Tables and Indexes

      You've learned enough of the fundamentals at this point to begin working on your first mini-project. Let's make a notes app! We'll begin with the initial database structure, which will give us the opportunity to review MySQL indexes.
    2. Render the Notes and Note Page

      Now that we have the initial database structure in place, let's create one page to display all of John Doe's notes, and then another page for each individual note.
    3. Introduction to Authorization

      In the previous episode, we added support for reading all notes that were created by a particular user. But, in doing so, we unwittingly introduced a major security concern. In this lesson, we'll discuss authorization, status codes, and magic numbers.
    4. Programming is Rewriting

      Before we move on to building a form to persist new notes to the database, let's take ten minutes to refactor our current code and discuss wrapping up APIs you don't own.
    5. Intro to Forms and Request Methods

      We're overdue, but it's finally time to dig into forms. In this lesson, we'll learn how to submit a form using two different request methods. Next, we'll discuss how our controller might detect whether a POST submission has occurred.
    6. Always Escape Untrusted Input

      In this lesson, we'll finally persist a new note to the database. But, in doing so, you'll be introduced to a new security concern that requires us to always escape user-provided input.
    7. Intro to Form Validation

      In this lesson, we'll review two layers of form validation: browser and server-side. We can use validation to ensure and confirm that the user submits their data in the exact format that we require.
    8. Extract a Simple Validator Class

      To make for a more flexible and readable experience, let's extract the basic validation rules we wrote in the previous episode into a dedicated Validator class.
  4. Project Organization (8)
    1. Resourceful Naming Conventions

      Let's take a short pause on the notes exercise, and instead switch our attention to general code organization. We'll start by switching to a common naming convention for resources.
    2. PHP Autoloading and Extraction

      Okay, buckle up. This will be the most dense episode yet, as we discuss a variety of topics related to project organization. We'll touch on document roots, helper functions, constants, PHP autoloading, and more.
    3. Namespacing: What, Why, How?

      It's time to discuss PHP namespacing, but don't worry: I'm going to make this incredibly easy to understand. If you can remember the days of storing your entire music collection locally, you'll grasp namespacing in seconds.
    4. Handle Multiple Request Methods From a Controller Action?

      Over the next three episodes, we'll review a number of refactors that are a bit more advanced. But first, we need to encounter a situation that necessitates the refactors. We'll use the example of a messy controller action that can respond to multiple request types.
    5. Build a Better Router

      In this episode, we'll build a better router that can handle and respond to any form request type. However, because forms only natively support GET and POST, we'll need to use a hidden input field to spoof the request type.
    6. One Request, One Controller

      With an improved router that can respond to multiple form request types, we can now refactor our controller actions to be more focused. We'll also discuss the importance of keeping your controller actions as simple as possible.
    7. Make Your First Service Container

      In this episode, we'll discuss the concept of a service container, and how it can help us organize our code and remove the need to manually construct the same dependencies over and over again.
    8. Updating With PATCH Requests

      The only remaining step for our first resource is to support editing notes. Luckily, most of the legwork has been completed at this point. We only need to create the form, and register a corresponding route and controller.
  5. Sessions and Authentication (5)
    1. PHP Sessions 101

      Welcome to a new chapter! We'll now begin to explore the world of PHP sessions. We'll start by discussing the concept of sessions, and how they can be used to persist data across multiple requests.
    2. Register a New User

      Now that we understand the basics of PHP session handling, we can build our first registration form. Once filled, we can create a new user in the database and then update the session to "mark" them as signed in.
    3. Introduction to Middleware

      In this episode, we'll discuss the concept of middleware, and how it can be used as a bridge between an incoming request and the core of your application. We'll create two middleware classes to handle route authorization for guests and authenticated users.
    4. Manage Passwords Like This For The Remainder of Your Career

      Up until this point, we've been storing passwords in clear text (gasp)! Let's fix that. In this episode, we'll discuss the importance of password hashing, and why it's necessary to protect your users' sensitive data. We'll also discuss the Bcrypt algorithm, and how it can be used to generate secure hashes.
    5. Log In and Log Out

      Now that we have a functioning registration form, we can finally build out the login system. As you'll see, there's a small handful of confusing, low-level steps that we need to follow - particularly when logging a user out.
  6. Refactoring Techniques (5)
    1. Extract a Form Validation Object

      For our first refactoring exercise, we'll extract a login form validation object. This approach will allow us to keep our controllers lean, clear, and easier to potentially reuse in other places.
    2. Extract an Authenticator Class

      Next up, we can further clean up our controller and improve clarity by extracting an Authenticator class. This new class can then be responsible for handling the actual authentication logic.
    3. The PRG Pattern (and Session Flashing)

      In this episode, we'll discuss the PRG (Post-Redirect-Get) pattern, and how it can be used to prevent duplicate form submissions. Currently, we're returning a view directly from the POST request in the event of failed validation, however, this is far from ideal. Let's review the problem, and then seek a solution.
    4. Flash Old Form Data to the Session

      Now that we understand how to temporarily "flash" data to the session, we can now return to the topic of displaying "old" form data to the user.
    5. Automatically Redirect Back Upon Failed Validation

      Next up, we'll learn how to automatically redirect back to the form upon failed validation. If we can manage to get this to work, we'll remove a significant amount of duplication and clutter from our various controllers.
  7. Meet Composer (2)
    1. Composer and Free Autoloading

      I think it's time to move on to a new chapter and finally discuss Composer. Composer is a world-class dependency manager that allows us to declare any and all libraries or packages that our project requires. Then, with a single command, we can install them in seconds. Even better, it ships with an excellent autoloader.
    2. Install Two Composer Packages: Collections and PestPHP

      Now that we've learned how to install Composer, itself, the next step is to pull in some packages! For demonstration purposes, we'll install two separate packages.
  8. Testing (1)
    1. Testing Approaches, Terms, and Considerations

      Let's dedicate one episode to discussing the different styles of testing, such as unit testing and feature testing. As part of this, we'll also touch on general workflow, common terms, and whether to follow test-first development.
  9. Wrapping Up (1)
    1. The Next Step in Your PHP Journey

      It's time to wrap up this series, but there's of course more to learn. In this episode, we will switch from our micro-framework to a fresh install of Laravel. We'll then review how many of its various features and components should be instantly familiar to you.

Continue Learning