CodeBlanks Logo Icon CodeBlanks
Free 4 levels PHP

PHP

Learn modern PHP 8.3 from variables to OOP, PDO and expert topics with hands-on projects.

The PHP course covers all levels with variables, OOP, PDO, REST APIs, security, design patterns, generators and deployment. Each level ends with projects and challenges.

  • 377 lessons
  • 30 h 24 min
  • 9 projects

No account needed, you can start right away. To save your progress, create a free account

Levels

The PHP course goes from zero to expert in four levels. Start at any level you like.
Not sure of your level? Take the placement test
Beginner

Learn PHP fundamentals: variables, data types, loops, arrays, functions and forms.

  • PHP basics
  • Variables
  • Data types
  • Operators
116 lessons · 8 h 24 min See lessons →
Intermediate

Build PHP apps with object-oriented programming, file handling, sessions, cookies and error handling.

  • Classes
  • Constructor
  • Inheritance
  • Visibility
115 lessons · 9 h 40 min See lessons →
Advanced

Learn advanced techniques with PDO, namespaces, Composer, REST APIs, security, middleware, tests and design patterns.

  • PDO basics
  • Prepared statements
  • CRUD operations
  • Namespaces
92 lessons · 7 h 45 min See lessons →
Expert

Master expert topics with generators, closures, reflection, performance, advanced security, modern PHP and deployment.

  • Generators
  • Closures and callbacks
  • Reflection
  • Performance
54 lessons · 4 h 35 min See lessons →

Projects you will build

At every level you combine what you learned into a real page.

How does it work?

Short explanation

Each lesson explains one concept in a few short cards; no long videos or walls of text.

Try it right away

Multiple choice, fill-in-the-blank and matching exercises lock in what you just learned.

Write it yourself

You write real code in the in-browser editor; it is checked instantly and you see the result live.

Curriculum

62 groups · 377 lessons · 30 h 24 min

Learn PHP fundamentals: variables, data types, loops, arrays, functions and forms.

1
PHP basics
6 lessons · 24 min
  1. 1 What is PHP? Learn that PHP is a server-side language and how it differs from the browser. 4 min
  2. 2 PHP tags Learn to embed PHP code in HTML with <?php and ?> tags. 4 min
  3. 3 Output with echo Learn to print text and variables to the screen with the echo statement. 4 min
  4. 4 Comments Learn to write single-line (//, #) and multi-line (/* */) comments in PHP. 3 min
  5. 5 phpinfo() and PHP version Learn the server configuration with phpinfo() and the PHP_VERSION constant. 4 min
  6. 6 Summary - PHP basics Combine tags, echo and comments to write your first PHP page. 5 min
2
Variables
6 lessons · 25 min
  1. 1 Declaring variables Learn to declare variables with the $ sign and assign values. 4 min
  2. 2 Variable naming rules Learn the letter, digit and underscore rules for variable names and case sensitivity. 4 min
  3. 3 Reassigning variables Learn to change a variable's value and increment or decrement it. 4 min
  4. 4 Combining variables Learn to combine two variables and assign the result to a new variable. 4 min
  5. 5 Checking variables with isset() and unset() Learn to check a variable's existence with isset() and remove it with unset(). 4 min
  6. 6 Summary - Variables Combine variable declaration, assignment and checks to build a user info card. 5 min
3
Data types
6 lessons · 25 min
  1. 1 string and int Identify and use the string and int data types. 4 min
  2. 2 float and bool Learn the float and bool types and the use of true and false. 4 min
  3. 3 null and empty value Learn the null type and how it differs from an empty string and 0. 4 min
  4. 4 Type checking with gettype() Learn to find a variable's type with the gettype() function. 4 min
  5. 5 Detailed output with var_dump() Learn to display a variable's type and value in detail with var_dump(). 4 min
  6. 6 Summary - Data types Combine string, int, float, bool and null types to build an inventory record. 5 min
4
Project: CalculatorProject
5 lessons · 25 min
  1. 1 Project: Calculator Overview of the 5-lesson calculator project: you will operate on two numbers and an operator. 4 min
  2. 2 Number input and operator selection Take two numbers and an operator to set up the operation. 5 min
  3. 3 Computing the operation Use if/elseif to select the operator and compute the result. 5 min
  4. 4 Handling error cases Add guards for division by zero and invalid operators. 5 min
  5. 5 Project final - Calculator Combine all parts and finalize a working calculator. 6 min
5
Operators
6 lessons · 25 min
  1. 1 Arithmetic operators Learn basic arithmetic with +, -, *, /, % and ** operators. 4 min
  2. 2 Assignment operators Learn shortcut assignments with =, +=, -=, *= and /=. 4 min
  3. 3 Comparison operators Learn to compare values with ==, ===, !=, <, >, <= and >=. 4 min
  4. 4 Logical operators Learn boolean logic and short-circuit evaluation with &&, || and !. 4 min
  5. 5 Concatenation and increment Learn string concatenation with . and .=, and increment/decrement with ++ and --. 4 min
  6. 6 Summary - Operators Combine arithmetic, comparison and logical operators to build a grade calculator. 5 min
6
String basics
6 lessons · 25 min
  1. 1 Creating strings Learn to create strings with single and double quotes and the difference between them. 4 min
  2. 2 Length with strlen() Learn the character length of a string with strlen(). 4 min
  3. 3 String concatenation Learn to concatenate strings with . and the common mistakes around it. 4 min
  4. 4 Variable interpolation in double quotes Learn how variables are interpolated inside double-quoted strings and the use of {} braces. 4 min
  5. 5 Escape sequences Learn how to write special characters inside strings with \n, \t, \\ and \". 4 min
  6. 6 Summary - String basics Build a greeting message combining string creation, concatenation and interpolation. 5 min
7
Conditionals
6 lessons · 25 min
  1. 1 The if statement Learn how to check a condition with if and the code block. 4 min
  2. 2 else and elseif Learn else and elseif chains for alternative cases. 4 min
  3. 3 The switch statement Learn multi-way selection with switch, case, break and default. 4 min
  4. 4 The ternary operator Learn to write a conditional expression in one line with ? :. 4 min
  5. 5 Comparison pitfalls Learn the difference between === and == and type coercion pitfalls. 4 min
  6. 6 Summary - Conditionals Build a day-of-the-week app using if, switch and the ternary operator. 5 min
8
Loops
6 lessons · 25 min
  1. 1 The for loop Learn to write operations that repeat a fixed number of times with the for loop. 4 min
  2. 2 The while loop Learn the while loop that runs as long as a condition holds. 4 min
  3. 3 The do-while loop Learn the do-while loop that runs at least once and how it differs from while. 4 min
  4. 4 The foreach loop Learn to walk through all elements of an array with foreach. 4 min
  5. 5 break and continue Learn to end a loop with break and skip a step with continue. 4 min
  6. 6 Summary - Loops Build a multiplication table using for, while and foreach. 5 min
9
Project: Shopping cartProject
5 lessons · 25 min
  1. 1 Project: Shopping cart Overview of the 5-lesson shopping cart project: store products in an array and compute totals. 4 min
  2. 2 Adding products to the cart Create a products array and add new products to the cart. 5 min
  3. 3 Displaying the cart List and display cart products with foreach. 5 min
  4. 4 Computing the total Multiply each product's price and quantity and compute the cart total. 5 min
  5. 5 Project final - Shopping cart Combine all parts and finalize a working shopping cart. 6 min
10
Array basics
6 lessons · 25 min
  1. 1 Creating arrays Learn to create arrays with the array() and [] syntax. 4 min
  2. 2 Accessing array elements Learn to access array elements by index with square brackets. 4 min
  3. 3 Element count with count() Learn how many elements an array has with the count() function. 4 min
  4. 4 Array output with print_r() Learn to print an array's contents in a readable form with print_r(). 4 min
  5. 5 Iterating an array Learn to walk through all elements of an array with for and foreach. 4 min
  6. 6 Summary - Array basics Combine array creation, access and iteration to build a weekly temperature list. 5 min
11
Array methods
6 lessons · 25 min
  1. 1 array_push() and array_pop() Learn to add elements to the end with array_push() and remove from the end with array_pop(). 4 min
  2. 2 array_shift() and array_unshift() Learn to remove from the start with array_shift() and add to the start with array_unshift(). 4 min
  3. 3 Merging with array_merge() Learn to merge two arrays into one with array_merge(). 4 min
  4. 4 Slicing with array_slice() Learn to take a portion of an array with array_slice(). 4 min
  5. 5 in_array() and array_search() Learn to check element existence with in_array() and find position with array_search(). 4 min
  6. 6 Summary - Array methods Build a queue management app using push, pop, merge and slice. 5 min
12
Associative arrays
6 lessons · 25 min
  1. 1 Key-value pairs Learn to create associative arrays with key-value pairs. 4 min
  2. 2 Accessing keys Learn to access values by key and the behavior for missing keys. 4 min
  3. 3 array_keys() and array_values() Learn to get all keys with array_keys() and all values with array_values(). 4 min
  4. 4 Key check with isset() Learn to check a key with isset() and the difference from array_key_exists(). 4 min
  5. 5 Iterating associative arrays Learn to walk both keys and values with foreach. 4 min
  6. 6 Summary - Associative arrays Build a user profile card with associative arrays and foreach. 5 min
13
Functions
6 lessons · 25 min
  1. 1 Defining functions Learn to define functions with the function keyword. 4 min
  2. 2 Calling functions Learn to call a function by its name with parentheses. 4 min
  3. 3 Returning values Learn to return a value from a function and use it at the call site. 4 min
  4. 4 Function scope Learn that variables inside a function are not visible outside. 4 min
  5. 5 Returning arrays from functions Learn to return an array from a function and use the result. 4 min
  6. 6 Summary - Functions Build a tax calculator using function declaration and return. 5 min
14
Parameters
6 lessons · 25 min
  1. 1 Functions with parameters Learn to pass parameters to a function and use them inside. 4 min
  2. 2 Default parameter values Learn to assign a default value to a parameter so it can be skipped at the call. 4 min
  3. 3 Multiple parameters Learn to define multiple parameters and call them in order. 4 min
  4. 4 Typed parameters Learn to declare a parameter's type (int, string, array) and get an error on wrong types. 4 min
  5. 5 Return type declaration Learn to declare a function's return type with the : type syntax. 4 min
  6. 6 Summary - Parameters Build a safe calculation function with parameters, defaults and type declarations. 5 min
15
Project: To-do listProject
5 lessons · 25 min
  1. 1 Project: To-do list Overview of the 5-lesson to-do project: manage tasks with arrays and functions. 4 min
  2. 2 Adding tasks Create a tasks array and write a function that adds a new task. 5 min
  3. 3 Listing tasks Number and list tasks with foreach. 5 min
  4. 4 Completing tasks Use an associative array to mark a task as completed. 5 min
  5. 5 Project final - To-do list Combine all parts and finalize a working to-do list. 6 min
16
Advanced string methods
6 lessons · 25 min
  1. 1 Replacing with str_replace() Learn to replace a substring in a string with str_replace(). 4 min
  2. 2 Slicing with substr() Learn to take a portion of a string with substr(). 4 min
  3. 3 Searching with strpos() Learn to find a substring's position with strpos() and its false return behavior. 4 min
  4. 4 Splitting with explode() Learn to split a string into an array by a delimiter with explode(). 4 min
  5. 5 Joining with implode() Learn to join an array into a string with a delimiter using implode(). 4 min
  6. 6 Summary - Advanced string methods Build a CSV line parser with str_replace, substr, explode and implode. 5 min
17
Superglobals
6 lessons · 25 min
  1. 1 What is a superglobal? Learn that superglobal variables are accessible from any scope. 4 min
  2. 2 Receiving data with $_GET Learn to read URL parameters with $_GET. 4 min
  3. 3 Receiving data with $_POST Learn to receive form-submitted data with $_POST. 4 min
  4. 4 $_SERVER and server info Learn server and request info (REQUEST_METHOD, HTTP_HOST) with $_SERVER. 4 min
  5. 5 Everything with $_REQUEST Learn to receive GET, POST and cookie data together with $_REQUEST. 4 min
  6. 6 Summary - Superglobals Build a page that displays URL parameters using $_GET and $_SERVER. 5 min
18
Forms
6 lessons · 25 min
  1. 1 Creating HTML forms Learn to create forms with method and action attributes. 4 min
  2. 2 Processing form data Learn to receive POST-submitted form data through $_POST. 4 min
  3. 3 Security with htmlspecialchars() Learn to close the XSS hole from user input with htmlspecialchars(). 4 min
  4. 4 Form validation basics Learn to check for empty fields and email format. 4 min
  5. 5 Showing error messages Learn to show validation errors to the user next to the form. 4 min
  6. 6 Summary - Forms Build a registration form combining form, $_POST and htmlspecialchars. 5 min
19
File inclusion
6 lessons · 25 min
  1. 1 Including files with include Learn to include another PHP file in a page with include. 4 min
  2. 2 Including files with require Learn to include files with require and the difference (fatal error) from include. 4 min
  3. 3 include_once and require_once Learn to include a file only once with include_once and require_once. 4 min
  4. 4 __DIR__ and path management Learn to manage file paths safely with the __DIR__ magic constant. 4 min
  5. 5 Layout and partial logic Learn to build a page layout by combining header, footer and content partials. 4 min
  6. 6 Summary - File inclusion Build a simple site skeleton with include, __DIR__ and partials. 5 min
20
Beginner finalFinal
5 lessons · 30 min
  1. 1 Challenge - Calculator Build an advanced calculator with functions, loops and conditionals. 6 min
  2. 2 Challenge - Secure feedback form Build a secure feedback form with an HTML form, $_POST and htmlspecialchars. 6 min
  3. 3 Challenge - Array operations Build a student grade board with associative arrays, foreach and array methods. 6 min
  4. 4 Challenge - Functions and loops Build an interest calculator with parameterized functions, loops and return. 6 min
  5. 5 Challenge - Mini CMS Build a simple content management page with include, arrays and a form. 6 min

Build PHP apps with object-oriented programming, file handling, sessions, cookies and error handling.

1
Classes
6 lessons · 30 min
  1. 1 Defining a class Learn to define a class with the class keyword. 5 min
  2. 2 Defining properties Learn to define properties inside a class and give default values. 5 min
  3. 3 Defining methods Learn to add methods (functions) inside a class. 5 min
  4. 4 In-class access with $this Learn to access the class's properties and methods with the $this pseudo-variable. 5 min
  5. 5 Instantiating with new Learn to create an instance from a class with the new operator. 5 min
  6. 6 Summary - Classes Build a user class with class, property, method and $this. 5 min
2
Constructor
6 lessons · 30 min
  1. 1 The __construct method Learn to run code on instantiation with the __construct magic method. 5 min
  2. 2 Passing parameters to the constructor Learn to pass parameters to the constructor and use them at instantiation. 5 min
  3. 3 Initializing properties Learn to assign initial values to properties in the constructor. 5 min
  4. 4 Class type declaration Learn to declare a class type on a constructor parameter so it only accepts that class. 5 min
  5. 5 The __destruct method Learn to clean up resources when an instance is destroyed with __destruct. 5 min
  6. 6 Summary - Constructor Build a bank account class with constructor, parameters and property initialization. 5 min
3
Inheritance
6 lessons · 30 min
  1. 1 Inheritance with extends Learn to inherit from a class with the extends keyword. 5 min
  2. 2 Accessing parent with parent:: Learn to access the parent's methods and constructor with parent::. 5 min
  3. 3 Method override Learn to override a parent method in a child class. 5 min
  4. 4 protected property and method Learn that protected access is only for the class and its subclasses. 5 min
  5. 5 Inheritance chain Learn to build a multi-level inheritance chain and propagate behavior. 5 min
  6. 6 Summary - Inheritance Build an animal class hierarchy with extends, parent:: and override. 5 min
4
Project: Utility libraryProject
5 lessons · 25 min
  1. 1 Project: Utility library Overview of the 5-lesson utility library: reusable structures with class + include. 4 min
  2. 2 Class skeleton Define a collection class and set up internal state with the constructor. 5 min
  3. 3 Adding methods Add add, remove and find methods to the class. 5 min
  4. 4 Using with file inclusion Move the class to a separate file and use it in another page with include. 5 min
  5. 5 Project final - Library Combine all parts and finalize the library as a working module. 6 min
5
Visibility
6 lessons · 30 min
  1. 1 public access Learn that public properties and methods are accessible everywhere. 5 min
  2. 2 protected access Learn that protected access is limited to the class and its subclasses. 5 min
  3. 3 private access Learn that private access is limited to the defining class only. 5 min
  4. 4 Encapsulation Learn to make internal state private and provide controlled access from outside. 5 min
  5. 5 Getter and setter methods Provide controlled access to private properties with getter and setter methods. 5 min
  6. 6 Summary - Visibility Build a temperature class with public, private, getter and setter. 5 min
6
Static members
6 lessons · 30 min
  1. 1 static property Learn to hold shared state on the class with static properties. 5 min
  2. 2 static method Learn to write methods callable without an instance with static methods. 5 min
  3. 3 In-class access with self:: Learn to access the class's static members from inside with self::. 5 min
  4. 4 Late static binding with static:: Learn late static binding with static:: and how it differs from self::. 5 min
  5. 5 static vs instance Learn the difference between static and instance members and when to use each. 5 min
  6. 6 Summary - Static members Build a counter class with static property, method and self::. 5 min
7
Class constants
6 lessons · 30 min
  1. 1 Class constants with const Learn to define class constants with the const keyword. 5 min
  2. 2 Accessing constants Learn to access class constants from outside and inside with the :: operator. 5 min
  3. 3 Class name with ::class Learn to get a class's fully qualified name as a string with ::class. 5 min
  4. 4 Class constants vs static Learn the difference between class constants and static properties. 5 min
  5. 5 Constant use cases Learn to define configuration values and status codes with class constants. 5 min
  6. 6 Summary - Class constants Build an order class with status constants using const, :: and ::class. 5 min
8
Project: Quiz appProject
5 lessons · 25 min
  1. 1 Project: Quiz app Overview of the 5-lesson quiz project: a Q&A app with OOP and arrays. 4 min
  2. 2 Designing a question class Design a class that holds a question, options and the correct answer. 5 min
  3. 3 Checking answers Write a method that compares the user's answer to the correct one. 5 min
  4. 4 Computing the score Walk all questions with foreach and compute the correct count. 5 min
  5. 5 Project final - Quiz app Combine all parts and finalize a working quiz app. 6 min
9
Interfaces
6 lessons · 30 min
  1. 1 Defining interfaces Learn to define a contract with the interface keyword. 5 min
  2. 2 Implementing with implements Learn to implement an interface's methods in a class with implements. 5 min
  3. 3 Multiple interfaces Learn to combine contracts by implementing multiple interfaces on a class. 5 min
  4. 4 Polymorphism Learn to use different classes implementing the same interface as a common type. 5 min
  5. 5 interface vs abstract Learn the difference between interface and abstract class and when to use each. 5 min
  6. 6 Summary - Interfaces Build a payment method system with interface, implements and polymorphism. 5 min
10
Abstract classes
6 lessons · 30 min
  1. 1 Defining abstract classes Learn to define an incomplete class template with abstract class. 5 min
  2. 2 abstract methods Learn to declare bodyless methods with abstract method and implement them in subclasses. 5 min
  3. 3 Abstract class inheritance Learn to extend an abstract class and implement its abstract methods. 5 min
  4. 4 Template method pattern Learn to set up a method skeleton in the abstract class and let subclasses fill in steps. 5 min
  5. 5 Constructor and abstract Learn to define a constructor in an abstract class and call it with parent:: in a subclass. 5 min
  6. 6 Summary - Abstract classes Build a data source system with abstract class, abstract method and template method. 5 min
11
Traits
6 lessons · 30 min
  1. 1 Defining traits Learn to define a reusable set of methods with the trait keyword. 5 min
  2. 2 Using traits with use Learn to include a trait's methods in a class with use. 5 min
  3. 3 Multiple traits Learn to combine capabilities by using multiple traits in a class. 5 min
  4. 4 Resolving method conflicts Learn to resolve conflicts in traits with the same method name using insteadof and as. 5 min
  5. 5 Trait vs inheritance Learn the difference between trait and inheritance and when to use each. 5 min
  6. 6 Summary - Traits Build logging-capable classes with trait, use and multiple traits. 5 min
12
Project: Blog appProject
5 lessons · 25 min
  1. 1 Project: Blog app Overview of the 5-lesson blog project: post management with OOP and forms. 4 min
  2. 2 Creating a post class Design a Post class that holds title, content and author. 5 min
  3. 3 Adding posts with a form Learn to create new posts with an HTML form and $_POST. 5 min
  4. 4 Displaying the post list Walk the posts array with foreach and display each post. 5 min
  5. 5 Project final - Blog Combine all parts and finalize a working blog app. 6 min
13
File handling
6 lessons · 30 min
  1. 1 Reading with file_get_contents() Learn to read a file's full content as a string with file_get_contents(). 5 min
  2. 2 Writing with file_put_contents() Learn to write a string to a file with file_put_contents(). 5 min
  3. 3 Opening files with fopen() Learn to open a file in different modes (r, w, a) with fopen(). 5 min
  4. 4 fwrite() and fread() Learn to write with fwrite() and read with fread(). 5 min
  5. 5 Closing files with fclose() Learn to close the file handle with fclose() and manage resources. 5 min
  6. 6 Summary - File handling Build a journal app with file_get_contents, file_put_contents and fopen. 5 min
14
File upload
6 lessons · 30 min
  1. 1 The $_FILES superglobal Learn to read file info from multipart form data with $_FILES. 5 min
  2. 2 move_uploaded_file() Learn to move the temporary file to a permanent location with move_uploaded_file(). 5 min
  3. 3 Validating file type Learn to validate the uploaded file's type (MIME). 5 min
  4. 4 File size limit Learn to check the file size limit for an upload. 5 min
  5. 5 Upload error handling Learn to read $_FILES['file']['error'] codes and give meaningful error messages. 5 min
  6. 6 Summary - File upload Build a profile picture upload with $_FILES, move_uploaded_file and validation. 5 min
15
Sessions
6 lessons · 30 min
  1. 1 Starting a session with session_start() Learn to start a session with session_start() and the session cookie. 5 min
  2. 2 Storing data with $_SESSION Learn to write data to the $_SESSION superglobal and carry it across pages. 5 min
  3. 3 Reading from a session Learn to read data from $_SESSION and check existence with isset(). 5 min
  4. 4 unset() and session_destroy() Learn to remove a single session variable with unset() and destroy the whole session with session_destroy(). 5 min
  5. 5 Login/logout logic Learn to build a simple login and logout flow with sessions. 5 min
  6. 6 Summary - Sessions Build a simple login system with session_start, $_SESSION and destroy. 5 min
16
Cookies
6 lessons · 30 min
  1. 1 Creating cookies with setcookie() Learn to create a cookie in the browser with setcookie(). 5 min
  2. 2 Reading cookies with $_COOKIE Learn to read cookies sent by the browser with the $_COOKIE superglobal. 5 min
  3. 3 Cookie expiration Learn to set a cookie's lifetime by passing an expiration to setcookie(). 5 min
  4. 4 Deleting cookies Learn to delete a cookie by setting it with a past expiration. 5 min
  5. 5 Session vs cookie Learn the difference between session and cookie and when to use each. 5 min
  6. 6 Summary - Cookies Build a theme preference (dark/light) app with setcookie, $_COOKIE and expiration. 5 min
17
Project: Contact formProject
5 lessons · 25 min
  1. 1 Project: Contact form Overview of the 5-lesson contact form project: sessions, files and validation together. 4 min
  2. 2 Form skeleton Build the contact form skeleton with name, email and message fields. 5 min
  3. 3 Validating data Write validation functions that check for empty fields and email format. 5 min
  4. 4 Integrating file upload Add an optional file upload (e.g. a screenshot) to the contact form. 5 min
  5. 5 Project final - Contact form Combine all parts and finalize a working contact form. 6 min
18
Error handling
6 lessons · 30 min
  1. 1 The try/catch block Learn to catch exceptions and handle error cases with try/catch. 5 min
  2. 2 Throwing exceptions with throw Learn to throw your own exception with throw new Exception(). 5 min
  3. 3 The Exception class Learn the Exception class's getMessage(), getCode() and getTrace() methods. 5 min
  4. 4 error_reporting configuration Learn to set which errors are shown with error_reporting and ini_set. 5 min
  5. 5 Custom exception classes Learn to define your own exception classes that extend Exception. 5 min
  6. 6 Summary - Error handling Build an age-checking function with try/catch, throw and custom exceptions. 5 min
19
Date and time
6 lessons · 30 min
  1. 1 Formatting dates with date() Learn to print dates with the date() function and format characters. 5 min
  2. 2 Timestamps with time() Learn to get and use the Unix timestamp with time(). 5 min
  3. 3 Parsing dates with strtotime() Learn to convert English date expressions to timestamps with strtotime(). 5 min
  4. 4 The DateTime class Learn object-oriented date operations with the DateTime class. 5 min
  5. 5 DateInterval and DatePeriod Learn date differences with DateInterval and walking date ranges with DatePeriod. 5 min
  6. 6 Summary - Date and time Build an event calendar app with date, strtotime and DateTime. 5 min
20
Intermediate finalFinal
5 lessons · 30 min
  1. 1 Challenge - OOP app Build a book library management system with classes, interfaces and traits. 6 min
  2. 2 Challenge - File and session Build a simple notebook app with file read/write and sessions. 6 min
  3. 3 Challenge - Multi-step registration form Build a secure registration app with a multi-step form and validation. 6 min
  4. 4 Challenge - Error handling Build a robust order system with try/catch, throw and custom exceptions. 6 min
  5. 5 Challenge - Mini API Build a simple task tracking API with classes, JSON and DateTime. 6 min

Learn advanced techniques with PDO, namespaces, Composer, REST APIs, security, middleware, tests and design patterns.

1
PDO basics
7 lessons · 35 min
  1. 1 What is PDO? Learn what PDO (PHP Data Objects) is and why it is used. 5 min
  2. 2 Connecting with PDO Learn to connect to a database with the PDO constructor and a DSN. 5 min
  3. 3 Running queries with query() Learn to run a SQL query directly with query(). 5 min
  4. 4 Single row with fetch() Learn to fetch a single row from a query result with fetch(). 5 min
  5. 5 All rows with fetchAll() Learn to get all rows of a query result as an array with fetchAll(). 5 min
  6. 6 Fetch mode constants Learn fetch modes like PDO::FETCH_ASSOC, PDO::FETCH_OBJ and PDO::FETCH_NUM. 5 min
  7. 7 Summary - PDO basics Build a user list app with connection, query, fetch and fetchAll. 5 min
2
Prepared statements
7 lessons · 35 min
  1. 1 Prepared statements with prepare() Learn to create a prepared statement with prepare() and why it is safer. 5 min
  2. 2 Running with execute() Learn to run a prepared statement with parameters using execute(). 5 min
  3. 3 Binding parameters with bindParam() Learn to bind a variable reference to a parameter with bindParam(). 5 min
  4. 4 Binding values with bindValue() Learn to bind a value to a parameter with bindValue() and how it differs from bindParam. 5 min
  5. 5 SQL injection and prevention Learn the SQL injection attack and how to prevent it with prepared statements. 5 min
  6. 6 Named placeholders Learn to write queries with named placeholders in the :name form. 5 min
  7. 7 Summary - Prepared statements Build a secure search app with prepare, execute, bindParam and named placeholders. 5 min
3
CRUD operations
7 lessons · 35 min
  1. 1 Inserting records with INSERT Learn to insert a new record with PDO and a prepared statement. 5 min
  2. 2 Reading records with SELECT Learn to run a SELECT query with PDO and read records. 5 min
  3. 3 Updating records with UPDATE Learn to update an existing record with PDO and a prepared statement. 5 min
  4. 4 Deleting records with DELETE Learn to delete a record with PDO and a prepared statement. 5 min
  5. 5 Affected rows with rowCount() Learn the number of rows affected by UPDATE, DELETE and INSERT with rowCount(). 5 min
  6. 6 Transaction management Learn to manage transactions with beginTransaction, commit and rollBack. 5 min
  7. 7 Summary - CRUD operations Build a user management app with INSERT, SELECT, UPDATE and DELETE. 5 min
4
Project: Blog with PDOProject
5 lessons · 25 min
  1. 1 Project: Blog with PDO Overview of the 5-lesson PDO blog project: post management with PDO. 4 min
  2. 2 Database structure Create the posts table and the PDO connection. 5 min
  3. 3 Adding and listing posts Add and list posts with INSERT and SELECT. 5 min
  4. 4 Editing and deleting posts Edit and delete existing posts with UPDATE and DELETE. 5 min
  5. 5 Project final - Blog with PDO Combine all parts and finalize a working blog with PDO. 6 min
5
Namespaces
7 lessons · 35 min
  1. 1 Defining namespaces Learn to package code with the namespace keyword. 5 min
  2. 2 Importing with use Learn to import a class from another namespace with use. 5 min
  3. 3 Aliases Learn to alias long class names with use ... as. 5 min
  4. 4 Global namespace Learn the global namespace with leading \ and global function calls. 5 min
  5. 5 Multi-level namespaces Learn the multi-level namespace structure in the Sub\Module\Class form. 5 min
  6. 6 PSR-4 autoloading Learn to write an autoloader that maps namespaces to file paths with PSR-4. 5 min
  7. 7 Summary - Namespaces Build a modular library structure with namespace, use, alias and PSR-4. 5 min
6
Composer
7 lessons · 35 min
  1. 1 What is Composer? Learn that Composer is a PHP package manager and what it provides. 5 min
  2. 2 The composer.json file Learn the composer.json structure and its basic fields. 5 min
  3. 3 Adding packages with require Learn to add a new package with composer require and version constraints. 5 min
  4. 4 Autoload (PSR-4) Learn Composer's PSR-4 autoload and the use of vendor/autoload.php. 5 min
  5. 5 Installing packages from Packagist Learn to search for and install packages from Packagist. 5 min
  6. 6 composer update and install Learn the difference between the composer install and update commands. 5 min
  7. 7 Summary - Composer Set up a project with managed dependencies using composer.json, require and autoload. 5 min
7
Regex
7 lessons · 35 min
  1. 1 Matching with preg_match() Learn to match a pattern in a string with preg_match(). 5 min
  2. 2 Replacing with preg_replace() Learn to replace matched patterns with a new value using preg_replace(). 5 min
  3. 3 All matches with preg_match_all() Learn to get all matches in a string with preg_match_all(). 5 min
  4. 4 Character classes Learn to narrow patterns with character classes like \d, \w, \s and [a-z]. 5 min
  5. 5 Quantifiers Learn to specify repetition with *, +, ? and {}. 5 min
  6. 6 Capture groups Learn to create capture groups with parentheses () and use backreferences. 5 min
  7. 7 Summary - Regex Build an email validation function with preg_match, preg_replace and character classes. 5 min
8
JSON and API
7 lessons · 35 min
  1. 1 Encoding with json_encode() Learn to convert a PHP value to a JSON string with json_encode(). 5 min
  2. 2 Parsing with json_decode() Learn to convert a JSON string to a PHP value with json_decode(). 5 min
  3. 3 JSON error handling Learn to catch JSON errors with json_last_error() and json_last_error_msg(). 5 min
  4. 4 Content-Type with header() Learn to set the JSON response header with header('Content-Type: application/json'). 5 min
  5. 5 REST API basics Learn the basics of REST architecture and the resource concept. 5 min
  6. 6 HTTP methods Learn the GET, POST, PUT and DELETE HTTP methods and their REST use. 5 min
  7. 7 Summary - JSON and API Build a simple user API with json_encode, header and HTTP methods. 5 min
9
Project: REST APIProject
5 lessons · 25 min
  1. 1 Project: REST API Overview of the 5-lesson REST API project: a task API with JSON, PDO and routing. 4 min
  2. 2 Routing structure Build a simple router with $_SERVER['REQUEST_METHOD'] and the URI. 5 min
  3. 3 CRUD endpoints Wire GET, POST, PUT and DELETE endpoints to PDO. 5 min
  4. 4 JSON response format Write a consistent JSON format for success and error responses. 5 min
  5. 5 Project final - REST API Combine all parts and finalize a working REST API. 6 min
10
Security
7 lessons · 35 min
  1. 1 Hashing with password_hash() Learn secure password hashing with password_hash() and PASSWORD_DEFAULT. 5 min
  2. 2 Verifying with password_verify() Learn to compare a plain password against a hash with password_verify(). 5 min
  3. 3 SQL injection prevention Reinforce protection against SQL injection with prepared statements. 5 min
  4. 4 XSS prevention Learn to protect against XSS with htmlspecialchars() and output escaping. 5 min
  5. 5 CSRF token generation Learn to generate a session-based CSRF token and verify it in forms. 5 min
  6. 6 Security headers Learn security headers like Content-Security-Policy, X-Frame-Options and HSTS. 5 min
  7. 7 Summary - Security Build a secure login form with password_hash, htmlspecialchars and CSRF. 5 min
11
Middleware
7 lessons · 35 min
  1. 1 The middleware pattern Learn what the middleware pattern is and its place in request processing. 5 min
  2. 2 Request/Response cycle Learn how middlewares chain between request and response. 5 min
  3. 3 Middleware chain Learn to chain multiple middlewares with arrays and callables. 5 min
  4. 4 Auth middleware Learn to write an auth middleware that checks the session. 5 min
  5. 5 Logging middleware Learn to write a logging middleware that records requests. 5 min
  6. 6 PSR-15 basics Learn the PSR-15 middleware interface and the MiddlewareInterface. 5 min
  7. 7 Summary - Middleware Build a protected API route structure with auth, logging and PSR-15. 5 min
12
Testing basics
7 lessons · 35 min
  1. 1 What is PHPUnit? Learn the PHPUnit testing framework and the goals of unit testing. 5 min
  2. 2 Writing your first test Learn to create a test class and a test method in PHPUnit. 5 min
  3. 3 Assertions Learn common assertions like assertEquals, assertTrue and assertContains. 5 min
  4. 4 Test layout (AAA) Learn the Arrange-Act-Assert test layout. 5 min
  5. 5 Test doubles (mock, stub) Learn to use mocks and stubs to isolate dependencies. 5 min
  6. 6 setUp and tearDown Learn the setup and teardown code that runs before and after each test with setUp() and tearDown(). 5 min
  7. 7 Summary - Testing basics Write a test suite for a calculator class with PHPUnit, assertions and mocks. 5 min
13
Design patterns
7 lessons · 35 min
  1. 1 The Singleton pattern Learn the Singleton pattern that ensures a single instance of a class. 5 min
  2. 2 The Factory pattern Learn to move object creation to a central factory method. 5 min
  3. 3 The Observer pattern Learn the Observer pattern where a subject notifies multiple observers. 5 min
  4. 4 The Strategy pattern Learn the Strategy pattern that packages interchangeable algorithms at runtime. 5 min
  5. 5 The Decorator pattern Learn the Decorator pattern that adds behavior without inheritance. 5 min
  6. 6 The Adapter pattern Learn the Adapter pattern that connects incompatible interfaces. 5 min
  7. 7 Summary - Design patterns Build a cart system with payment method selection using Singleton, Factory and Strategy. 5 min
14
Advanced finalFinal
5 lessons · 30 min
  1. 1 Challenge - PDO and API Build a secure product API with PDO, prepared statements and JSON. 6 min
  2. 2 Challenge - Security app Build a full authentication flow with password_hash, CSRF and security headers. 6 min
  3. 3 Challenge - Design patterns Build a flexible notification system with Factory, Strategy and Observer. 6 min
  4. 4 Challenge - Writing tests Write a test suite for an order service with PHPUnit, mocks and the AAA layout. 6 min
  5. 5 Challenge - Mini framework Build a simple mini framework core with middleware, routing and PDO. 6 min

Master expert topics with generators, closures, reflection, performance, advanced security, modern PHP and deployment.

1
Generators
7 lessons · 35 min
  1. 1 The yield keyword Learn to write a function that yields values and preserves state. 5 min
  2. 2 The Generator class Learn the Generator class's current(), next() and send() methods. 5 min
  3. 3 Memory efficiency Learn how generators save memory with large datasets. 5 min
  4. 4 Infinite generators Learn generators that produce infinite sequences and using them in finite loops. 5 min
  5. 5 Delegation with yield from Learn to delegate another generator or array with yield from. 5 min
  6. 6 Pipeline with generators Learn to chain multiple generators as a pipeline for data flow. 5 min
  7. 7 Summary - Generators Build a large log file parser with yield, yield from and pipelines. 5 min
2
Closures and callbacks
7 lessons · 35 min
  1. 1 The Closure class Learn that anonymous functions are instances of the Closure class. 5 min
  2. 2 Capturing variables with use Learn to capture outer scope variables into a closure with use. 5 min
  3. 3 Arrow functions (fn) Learn to write short arrow functions with automatic variable capture using fn =>. 5 min
  4. 4 The callable type Learn to make a function accept another function with the callable type declaration. 5 min
  5. 5 Higher-order functions Learn to write higher-order functions that return or accept functions. 5 min
  6. 6 Closure binding (bindTo) Learn to bind a closure to a different object with bindTo(). 5 min
  7. 7 Summary - Closures and callbacks Build a functional filter/map chain with closures, arrow functions and callables. 5 min
3
Reflection
7 lessons · 35 min
  1. 1 What is reflection? Learn to query class and method info at runtime with the Reflection API. 5 min
  2. 2 ReflectionClass Learn a class's properties, methods and constants with ReflectionClass. 5 min
  3. 3 ReflectionMethod Learn a method's parameters, visibility and return type with ReflectionMethod. 5 min
  4. 4 ReflectionProperty Learn a property's type and read private values with ReflectionProperty. 5 min
  5. 5 Reading annotations Learn to read doc comments and #[] attributes with reflection. 5 min
  6. 6 Dynamic method invocation Learn to invoke a method at runtime with reflection. 5 min
  7. 7 Summary - Reflection Build a simple DI container with ReflectionClass, ReflectionMethod and attributes. 5 min
4
Performance
7 lessons · 35 min
  1. 1 OPcache configuration Learn to boost performance by keeping PHP bytecode in memory with OPcache. 5 min
  2. 2 Profiling tools Learn to profile and find bottlenecks with Xdebug and XHProf. 5 min
  3. 3 Memory management Learn to manage memory with memory_get_usage() and breaking reference cycles. 5 min
  4. 4 Benchmarking Learn to write benchmarks that compare code pieces with microtime(). 5 min
  5. 5 The N+1 query problem Learn the N+1 query problem in ORM and data loading and the eager loading solution. 5 min
  6. 6 Lazy loading Learn lazy loading approaches that load data only when needed. 5 min
  7. 7 Summary - Performance Build an optimized data service with OPcache, benchmarks and eager loading. 5 min
5
Advanced security
7 lessons · 35 min
  1. 1 password_needs_rehash() Learn to upgrade outdated hashes to a new algorithm with password_needs_rehash(). 5 min
  2. 2 Rate limiting Learn to prevent brute force by applying rate limiting on login and API endpoints. 5 min
  3. 3 Security headers (CSP, HSTS) Learn to configure Content-Security-Policy, HSTS and X-Content-Type-Options headers. 5 min
  4. 4 Session fixation prevention Learn to prevent session fixation attacks with session_regenerate_id(). 5 min
  5. 5 Input sanitization Learn to sanitize and validate input with filter_input() and filter_var(). 5 min
  6. 6 Secure file upload Learn MIME checks, random names and storage separation for secure file upload. 5 min
  7. 7 Summary - Advanced security Build a hardened app skeleton with rate limiting, CSP and secure upload. 5 min
6
Modern PHP
7 lessons · 35 min
  1. 1 readonly property Learn properties that can be written only once with readonly property. 5 min
  2. 2 Enums Learn to define and use type-safe constants with enum. 5 min
  3. 3 The match expression Learn to write shorter and safer conditionals than switch with the match expression. 5 min
  4. 4 Named arguments Learn named arguments that pass values by parameter name. 5 min
  5. 5 Fibers Learn to write thread-like coroutines with the Fiber class. 5 min
  6. 6 First-class callable syntax Learn the first-class callable syntax that creates closures with .... 5 min
  7. 7 Summary - Modern PHP Build a modern state machine with readonly, enum, match and named arguments. 5 min
7
Deployment
7 lessons · 35 min
  1. 1 PHP with Docker Learn to set up a PHP development environment with a Dockerfile and docker-compose. 5 min
  2. 2 PHP-FPM configuration Learn PHP-FPM pool settings and the process manager. 5 min
  3. 3 Nginx configuration Learn to configure Nginx with PHP-FPM as a reverse proxy. 5 min
  4. 4 CI/CD basics Learn to set up a continuous integration pipeline with GitHub Actions or GitLab CI. 5 min
  5. 5 Environment management Learn to manage environment variables with a .env file and getenv(). 5 min
  6. 6 Zero-downtime deployment Learn zero-downtime deployment with symlink swapping and atomic deploys. 5 min
  7. 7 Summary - Deployment Build a full deployment pipeline with Docker, PHP-FPM, Nginx and CI. 5 min
8
Expert finalFinal
5 lessons · 30 min
  1. 1 Challenge - Generators and closures Build an ETL that processes a large data stream with generators, yield from and closures. 6 min
  2. 2 Challenge - Reflection app Build an automatic serializer that works with reflection and attributes. 6 min
  3. 3 Challenge - Performance optimization Build an optimized report service with OPcache, benchmarks and eager loading. 6 min
  4. 4 Challenge - Secure architecture Build a hardened API with rate limiting, CSP and session_regenerate_id. 6 min
  5. 5 Challenge - Full PHP app Build a modern task management system with readonly, enum, match, fibers and Docker. 6 min

Lessons are free, an account keeps your progress

You do not have to sign up. If you do, you continue where you left off and never lose your work.

  • Progress saved on every device
  • Earn XP and badges
  • Keep your daily streak
  • Get a certificate when you finish
create a free account

Frequently asked questions

Are the PHP lessons free?

Yes. All 377 lessons of the PHP course are free and you can start without an account.

Do I need any prior knowledge?

No. The beginner level starts from zero; a browser is all you need. If you already know the basics, start at a higher level.

How long does the course take?

Lessons take 2–8 minutes. The whole course is about 30 hours; with 15–20 minutes a day you can finish in a few months.

Do I get a certificate?

Yes. When you complete the course with a free account, a verifiable certificate is issued in your name.

Will I lose my progress without an account?

Without an account your progress is kept only in your current browser. When you create a free account it is moved to your account.

Next step C#

Learn modern C# 12 and .NET 8 from variables to OOP, async/await, LINQ and expert topics with hands-on projects.