Problem
Web apps and APIs set HTTP status explicitly:
http_response_code(404);
echo 'Not found';
bin/serve.php maps uncaught exceptions to 500 (#152), but user scripts cannot return 404, 201, or 422 from compiled PHP. No VM builtin exists; docs/capabilities.md does not list http_response_code.
MiniWebApp (#67) and JSON API routes (#61) need correct status codes for missing resources and validation errors.
Goal
http_response_code(?int $code = null): int in VM (JIT/AOT deferred):
http_response_code(404) sets status for the current response
http_response_code() with no args returns the current code (default 200)
- Invalid codes warn or return
false per PHP semantics
Implementation hints
- VM: store status on
Runtime or a request-scoped Web\ResponseContext shared with lib/Web/DevServer.php respond().
- Serve path:
DevServer::respond() reads stored code instead of hard-coded 200/500 when set.
- AOT CGI: mirror in
lib/AOT/runtime/ or document VM callback until native lowering exists.
- Register in
ext/standard/Module.php; add ext/standard/http_response_code.php handler.
- PHPT:
test/real/cases/web_http_response_code.phpt — set 404, echo body, assert status line in raw HTTP response from serve helper.
Acceptance criteria
./phpc serve 127.0.0.1:8080 examples/001-SimpleWeb
# script returns 404 when ?missing=1 on a not-found handler
curl -s -o /dev/null -w '%{http_code}' 'http://127.0.0.1:8080/notfound.php'
Returns 404 when handler calls http_response_code(404).
Verification (local only)
./script/ci-local.sh --filter web_http_response_code
# or Docker:
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
./script/ci-local.sh --filter web_http_response_code
Do not require GitHub Actions.
Dependencies
Related
Files
ext/standard/, lib/Web/DevServer.php, lib/Runtime.php
Problem
Web apps and APIs set HTTP status explicitly:
bin/serve.phpmaps uncaught exceptions to 500 (#152), but user scripts cannot return 404, 201, or 422 from compiled PHP. No VM builtin exists;docs/capabilities.mddoes not listhttp_response_code.MiniWebApp (#67) and JSON API routes (#61) need correct status codes for missing resources and validation errors.
Goal
http_response_code(?int $code = null): intin VM (JIT/AOT deferred):http_response_code(404)sets status for the current responsehttp_response_code()with no args returns the current code (default 200)falseper PHP semanticsImplementation hints
Runtimeor a request-scopedWeb\ResponseContextshared withlib/Web/DevServer.phprespond().DevServer::respond()reads stored code instead of hard-coded200/500when set.lib/AOT/runtime/or document VM callback until native lowering exists.ext/standard/Module.php; addext/standard/http_response_code.phphandler.test/real/cases/web_http_response_code.phpt— set 404, echo body, assert status line in raw HTTP response from serve helper.Acceptance criteria
Returns
404when handler callshttp_response_code(404).Verification (local only)
Do not require GitHub Actions.
Dependencies
ob_end_flush)Related
header('Location: …'))Files
ext/standard/,lib/Web/DevServer.php,lib/Runtime.php