PHP Course

PHP is the server-side language behind WordPress, Wikipedia, Laravel and Symfony applications and a large share of the web. This course teaches modern PHP 8.5 — typed, object-oriented and secure — from your first script through arrays, functions and classes to forms, sessions, databases with PDO, Composer and testing, finishing with a complete guestbook web application.

What you'll learn

The course has 64 lessons in eleven parts:

  • Getting Started — what PHP is, installing it, running scripts, and how PHP serves web pages.
  • Basics — syntax, variables, types, numbers, type juggling, operators and constants.
  • Control Flow — if, switch and match, and loops.
  • Strings — string functions, printf formatting, Unicode with mb_*, and regular expressions.
  • Arrays — lists, associative arrays, array functions, sorting, nested data, destructuring and spread.
  • Functions — parameters, named arguments, type declarations, scope, closures, the pipe operator and recursion.
  • Object-Oriented PHP — classes, constructors, property hooks, inheritance, interfaces, traits, enums, readonly objects and namespaces.
  • Errors & Iteration — exceptions and generators.
  • PHP on the Web — forms, validation and escaping, sessions, cookies, headers, uploads, templates and routing.
  • Files, Data & Databases — files, JSON and HTTP, dates, PDO, prepared statements, transactions and security.
  • Modern PHP & Projects — Composer, PHPUnit, what's new in PHP 8.5, debugging and a final project.

Every example in the course was run with PHP 8.5 and the output shown is exactly what it produced. Command-line examples ran with the php command; web examples ran on PHP's built-in web server, with each request and the response the browser received shown on the page. The Try it yourself editors let you change any example and copy it to run on your own computer.

No previous programming experience is required, though knowing a little HTML helps with the web lessons.

Practice

  • Playground — a starter script to copy and experiment with.
  • Exercises — fill-in-the-blank tasks and programming challenges with solutions.
  • Quiz — test your understanding across the whole course.
  • Syllabus & Study Plan — learning outcomes and a week-by-week schedule.

Lessons

Getting Started

  1. Introduction to PHP
  2. Installing PHP
  3. Your First Script
  4. PHP and the Web

Basics

  1. Syntax and Comments
  2. Variables
  3. Data Types
  4. Numbers and Math
  5. Type Juggling and Conversion
  6. Operators
  7. Constants

Control Flow

  1. if, else and elseif
  2. switch and match
  3. while Loops
  4. for and foreach Loops

Strings

  1. Strings
  2. String Functions
  3. Formatting Output
  4. Multibyte Strings and Unicode
  5. Regular Expressions

Arrays

  1. Arrays
  2. Associative Arrays
  3. Array Functions
  4. Sorting Arrays
  5. Multidimensional Arrays
  6. Destructuring and Spread

Functions

  1. Functions
  2. Parameters and Arguments
  3. Type Declarations
  4. Scope and Static Variables
  5. Closures and Callables
  6. Recursion

Object-Oriented PHP

  1. Classes and Objects
  2. Constructors
  3. Visibility and Property Hooks
  4. Static Members and Class Constants
  5. Inheritance
  6. Abstract Classes and Interfaces
  7. Traits
  8. Enums
  9. Readonly and Immutability
  10. Magic Methods
  11. Namespaces and Autoloading

Errors & Iteration

  1. Errors and Exceptions
  2. Generators and Iterators

PHP on the Web

  1. Handling Forms
  2. Validation and Escaping
  3. Sessions
  4. Cookies
  5. Headers, Status Codes and Redirects
  6. File Uploads
  7. Templates and Output Buffering
  8. Routing and Front Controllers

Files, Data & Databases

  1. Files and Directories
  2. JSON and HTTP Requests
  3. Dates and Times
  4. Databases with PDO
  5. Prepared Statements and Transactions
  6. Web Security Essentials

Modern PHP & Projects

  1. Composer and Packages
  2. Testing with PHPUnit
  3. What's New in PHP 8.5
  4. Debugging and Best Practices
  5. Project: A Guestbook

Practice

  1. PHP Playground
  2. PHP Exercises
  3. PHP Quiz
  4. Syllabus & Study Plan
Where to start: begin with Introduction and install PHP in lesson 2 so you can run every example yourself. Afterwards, learn to design databases with our SQL course, or keep your projects under version control with Git.