Runtime Checkpoint

Runtime Checkpoint

Hands-on Checkpoint

Organise the project into files the right way, run it from the browser and the terminal, and trace one request — on your own computer.

40–60 min

The Challenge

Before launch, Marcus wants the project in its final shape: settings in one place, functions in src/, one public page and one terminal script — each loaded the safe way. And he wants Mia to explain, in her own words, what PHP does with one request from start to end.

This checkpoint runs on your own computer, with the PHP you installed in Act 01, because it's about files, folders and the terminal — things a single-file Playground can't show. Build the project below, run it both ways, and write the trace.

What You Need to Do

  • Create a folder bookbay with config.php, src/time-helpers.php, src/slots.php, src/prices.php, src/bookings.php, public/booking.php and bin/send-reminders.php.
  • config.php returns an array with the shop name and the holiday percentage; nothing else sets variables at the top level of a file in src/ (chapter 2).
  • formatTime() lives only in src/time-helpers.php, and both slots.php and prices.php load it with require_once — so loading both never redeclares it (chapter 2).
  • Every require and require_once builds its path from __DIR__ (chapter 2).
  • public/booking.php reads $_GET["date"] once and passes it to slotsFor(); served with php -S localhost:8000 -t public, the URL /booking.php?date=2026-11-10 shows the slots for 2026-11-10 (chapters 1 and 2).
  • bin/send-reminders.php takes the date from $argv[1] and prints the reminder list. It must give the same output when run from the bookbay folder, from inside bin, and from a completely different folder (chapter 3).
  • Write a short trace of one visit to /booking.php?date=2026-11-10: who receives the request, what PHP fills in, which files are loaded and in which order, what is sent back, and what happens to every variable afterwards (chapters 3 and 4).
Stuck? A Few Hints
  • If the page shows the wrong date, look for a file in src/ that sets $date at its top level (chapter 2).
  • "Cannot redeclare function formatTime()" means a file that declares it was loaded twice: use require_once (chapter 2).
  • "Failed to open stream" only from some folders means a ../ path: start it from __DIR__ (chapter 2).
  • For the trace, follow the diagram in chapter 3 — request begins, script runs (with OPcache, compiled code is reused), request ends — and add the file names.

Before You Move On

If your page and your terminal script both work, from any folder, you've built the shape every PHP project has — and you can explain what happens on each request, which is exactly what you need when something goes wrong in production. Next: objects. The booking arrays from Act 08 are about to become real Booking objects that check their own data.