Skip to content

Examples: 007-ThrowsWeb — throw/catch presenter app (post-#195/#57) #2076

@PurHur

Description

@PurHur

Problem

Shipped examples 000–006 cover CLI, simple CGI, sessions, and multipart upload, but none demonstrate throw / catch / HTTP 500 paths. #195 tracks language lowering; presenters lack a copy-paste web demo like 005-SessionsWeb / 006-FileUploadWeb.

MiniWebApp contact validation (#697) and API errors will eventually use exceptions instead of echo + exit.

Goal

Add examples/007-ThrowsWeb/ with:

  • example.php — form POST; invalid input throw new Exception(...); caught → friendly HTML; uncaught path documented for phpc serve
  • phpc.json manifest
  • README.md with VM curls + gate ladder
  • Optional: ./phpc init --profile throwsweb follow-up (separate issue)

Acceptance criteria

./phpc lint examples/007-ThrowsWeb/example.php   # green after #195 VM
./phpc run examples/007-ThrowsWeb/example.php
./phpc serve 127.0.0.1:8080 examples/007-ThrowsWeb
curl -sf -X POST -d 'email=bad' http://127.0.0.1:8080/example.php | grep -i invalid
  • Listed in examples/README.md run matrix (VM column; JIT/AOT deferred)
  • test/unit/ExamplesCompileTest.php discovers 007 when lint green
  • examples-web-smoke.sh slice opt-in via THROWS_WEB_SMOKE_GATE=0 default until stable

Verification (local / Docker)

./script/ci-fast.sh
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev ./script/ci-fast.sh

No GitHub Actions required.

Dependencies

Links


Implementation hints (batch 120)

Proposed tree

examples/007-ThrowsWeb/
  example.php          # POST form; caught Exception → HTML; doc uncaught 500 path
  phpc.json            # { "entry": "example.php", "binary": ".phpc/bin/app" }
  README.md            # curls + gate ladder

Gate ladder (mirror 005/006)

Step Env / command Issue
VM lint + run ./phpc lint / run / serve this issue
Web smoke THROWSWEB_WEB_SMOKE_GATE=1 #2093
Init scaffold ./phpc init --profile throwsweb #2092
Init parity check-init-throwsweb-parity.sh #2086
AOT link THROWSWEB_AOT_LINK_GATE=1 #2101
AOT execute THROWSWEB_AOT_SMOKE_GATE=1 #2101
Benchmark row BENCH_THROWSWEB=1 rebuild-examples #2113
doctor ./phpc doctor --gates #2102

Tests to touch

Makefile / CI

  • make web-smoke — include lint path when dir exists
  • Do not default-on ci-local until VM curls stable (same as early 005)

File map (language)

Need Blocker
throw new Exception(...) #195
catch (Exception $e) #57 + #2084 PHPTs
$e->getMessage() #58 method calls

Verify on harness:

docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev ./script/ci-fast.sh

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:webWeb / CGI / superglobalsenhancementNew feature or requestphase-5:reference-appPhase 5 – reference web application

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions