koans.app

PHP Koans

PHP was built for the web and still runs a large part of it, from blogs and online shops to large sites and web applications. A request comes in, PHP builds the page or the answer, and sends it back. Modern PHP has types, classes, enums, match and closures, a long way from its early days. These koans cover strings and arrays, functions, classes and interfaces, enums, generators and errors.

79 koans in 12 groups, tested with PHPUnit. Each is a small program whose tests fail: replace every ___ until they pass.

Start the path

Awakening

How a koan checks your answers, and PHP's first ideas: truth, null, types and equality.

  1. Assertions
  2. Truthiness
  3. null
  4. Types
  5. Equality
  6. Errors

Numbers

Integers and floats, conversion, rounding and formatting.

  1. Arithmetic
  2. Integers and floats
  3. Conversion
  4. Math functions
  5. Formatting numbers
  6. Random numbers

Strings

Quotes, interpolation, heredocs, string functions, formatting and regular expressions.

  1. Quotes and interpolation
  2. Heredoc and nowdoc
  3. String functions
  4. Searching strings
  5. Splitting and replacing
  6. sprintf
  7. Bytes and characters
  8. Regular expressions

Arrays

PHP's one collection: lists and maps, changing them, transforming, sorting and destructuring.

  1. Lists
  2. Associative arrays
  3. Adding and removing
  4. Searching arrays
  5. Map, filter and reduce
  6. Sorting
  7. Slicing and merging
  8. Destructuring
  9. More array functions

Control flow

Conditions, match, switch, and loops.

  1. Conditions
  2. Null coalescing
  3. match
  4. switch
  5. Loops

Functions

Typed parameters, defaults, named arguments, closures, arrow functions and callables.

  1. Typed functions
  2. Defaults and nullable types
  3. Named arguments
  4. Variadics and spread
  5. References
  6. Closures
  7. Callables
  8. The pipe operator
  9. Recursion
  10. Static variables

Classes

Classes and objects: constructors, visibility, static members, inheritance, interfaces, traits and magic methods.

  1. Classes and objects
  2. Constructors
  3. Visibility
  4. Static members
  5. Inheritance
  6. Abstract classes and interfaces
  7. Traits
  8. Magic methods
  9. Property hooks
  10. Late static binding

Enums and types

Enums, the nullsafe operator, built-in interfaces, and objects as values.

  1. Enums
  2. Backed enums
  3. The nullsafe operator
  4. Built-in interfaces
  5. Comparing objects
  6. Attributes
  7. Type juggling

Generators and fibers

Functions that yield values one at a time, and functions that pause and resume.

  1. Generators
  2. Keys and delegation
  3. Sending values
  4. Lazy pipelines
  5. Fibers

Errors

Exceptions and errors: catching, cleaning up, your own exceptions, and chaining.

  1. try, catch and finally
  2. The hierarchy
  3. Custom exceptions

The standard library

JSON, dates, SPL data structures, and objects that compare strings.

  1. JSON
  2. Dates
  3. SPL data structures
  4. Arbitrary precision
  5. Weak maps

Puzzles

Small programs that put the path together: read them closely and predict what they do.

  1. FizzBuzz
  2. Word frequencies
  3. Anagrams
  4. Run-length encoding
  5. Roman numerals