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.
Awakening
How a koan checks your answers, and PHP's first ideas: truth, null, types and equality.
Numbers
Integers and floats, conversion, rounding and formatting.
Strings
Quotes, interpolation, heredocs, string functions, formatting and regular expressions.
- Quotes and interpolation
- Heredoc and nowdoc
- String functions
- Searching strings
- Splitting and replacing
- sprintf
- Bytes and characters
- Regular expressions
Arrays
PHP's one collection: lists and maps, changing them, transforming, sorting and destructuring.
- Lists
- Associative arrays
- Adding and removing
- Searching arrays
- Map, filter and reduce
- Sorting
- Slicing and merging
- Destructuring
- More array functions
Control flow
Conditions, match, switch, and loops.
Functions
Typed parameters, defaults, named arguments, closures, arrow functions and callables.
- Typed functions
- Defaults and nullable types
- Named arguments
- Variadics and spread
- References
- Closures
- Callables
- The pipe operator
- Recursion
- Static variables
Classes
Classes and objects: constructors, visibility, static members, inheritance, interfaces, traits and magic methods.
- Classes and objects
- Constructors
- Visibility
- Static members
- Inheritance
- Abstract classes and interfaces
- Traits
- Magic methods
- Property hooks
- Late static binding
Enums and types
Enums, the nullsafe operator, built-in interfaces, and objects as values.
Generators and fibers
Functions that yield values one at a time, and functions that pause and resume.
Errors
Exceptions and errors: catching, cleaning up, your own exceptions, and chaining.
The standard library
JSON, dates, SPL data structures, and objects that compare strings.
Puzzles
Small programs that put the path together: read them closely and predict what they do.