Skip to content

Stdlib: fopen, fwrite, fclose, and file_put_contents for templates and logs #194

@PurHur

Description

@PurHur

Problem

Small PHP apps read/write files for HTML templates, config, and logs. Today only VM host calls file_get_contents in bin/serve.php; user PHP has no fopen/file_put_contents in the compiler stdlib.

#62 covers file_get_contents; #171 covers streaming via readfile.

Goal

Implement a minimal, safe file I/O subset for web apps (read/write text files under a configurable root).

Tasks

  • VM builtins: fopen, fread, fwrite, fclose, file_put_contents, file_exists, is_file, is_dir
  • Resource type in VM (Variable::TYPE_RESOURCE) or simplify to path strings + internal handles
  • JIT/AOT: start VM-only; document in capability matrix
  • Optional docroot jail: paths must resolve under project public/ or phpc.json root (DevEx: phpc.json project manifest (entry, includes, public assets) #106)
  • PHPT: write log line, include template file
  • Error modes: @ suppression, warnings on missing file

Acceptance criteria

file_put_contents(__DIR__ . '/cache/hit.txt', 'ok');
echo file_get_contents(__DIR__ . '/cache/hit.txt');

Runs in VM; JIT/AOT documented as follow-up.

Dependencies

Files

  • ext/standard/ new modules, lib/VM.php, docs/capabilities.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:webWeb / CGI / superglobalsenhancementNew feature or requestphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions