typestar

Language basics

27 steps in 9 sets of PHP.

PHP runs most of the web that is not a framework demo: WordPress, Wikipedia, and a long tail of applications that pay salaries. The language those sites run on today is not the one its reputation remembers — PHP 8 has a JIT, enums, match expressions, named arguments, and a type system that catches real mistakes. The dollar sigil on every variable and the arrow on every method make it a distinctive language under your fingers.

This tour covers modern PHP as a language: variables and interpolation, arrays (the one data structure that is secretly three), closures and arrow functions, classes with promoted constructors, enums, and the null-safety operators that tamed a billion notices. The encore ships complete command-line programs. Every seed opens with the <?php tag real files carry, parses under php -l, and runs start to finish on PHP 8.

Start this tour

Variables & types

  • Variables & typesDollar-sign variables and the types PHP infers from their values.
  • String interpolationDouble quotes splice variables into strings; single quotes leave them alone.
  • Numbers & castsInteger and float arithmetic, plus the casts that tame loose strings.

Control flow

  • if and elseifBranching on a value with PHP's one-word elseif and the ternary.
  • The match expressionPHP 8's answer to switch: strict comparison, a return value, no fallthrough.
  • foreach loopsOne loop, three shapes: values only, key with value, and by reference.

Arrays

  • ArraysBuilding, growing, slicing, and sorting PHP's list-shaped arrays.
  • Associative arraysString keys with =>, plus the operators that handle missing ones.
  • Array functionsmap, filter, and sum: transforming arrays without writing a loop.

Functions

Strings & regex

Classes

  • Constructor promotionPHP 8 constructors that declare, type and assign properties in one stroke.
  • InterfacesOne contract, two shapes, one loop that cares about neither.
  • TraitsSharing behavior across classes without inheritance.

Null & errors

  • Null coalescingThe three operators that tamed a billion undefined-index notices.
  • Exceptionstry, catch, finally and a custom exception class of your own.
  • Backed enumsAn enum whose cases carry string values — and behavior of their own.

Modern touches

Encore

  • word_freq.phpA word-frequency report over an inline passage, built from array functions.
  • grade_report.phpPer-student averages, letter grades, and a class summary table.
  • link_checker.phpPulls every href out of an HTML string and buckets the link styles.

The other PHP tours