Skip to content

Stdlib: extract() and compact() for PHP template includes #275

Description

@PurHur

Problem

The reference MiniWebApp (#67, #246) and normal PHP micro-frameworks pass data into templates with:

$data = ['title' => 'Home', 'name' => $name];
extract($data);
include __DIR__ . '/../templates/home.php';

extract() / compact() are not in docs/capabilities.md or ext/standard/. Without them, templates either pollute scope manually or avoid include until much later.

Goal

VM + JIT support for:

  • extract(array $vars, int $flags = EXTR_SKIP) — at minimum EXTR_SKIP on string keys
  • compact(string ...$names) — build array from local variables (v1: literal name list only)

Scope

  • VM wrappers in ext/standard/ (may delegate to PHP extract/compact initially)
  • JIT callouts or native lowering for packed string-key arrays
  • PHPT: template include after extract(['name' => 'Dev']) echoes variable
  • Register in ext/standard/Module.php; update script/capability-matrix.php output
  • Document blocker link from Reference: MiniWebApp lint-first skeleton (examples/003-MiniWebApp) #246 README table

Acceptance criteria

docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  ./phpc run -r '$t=["name"=>"Dev"]; extract($t); echo $name;'

prints Dev in VM; same after JIT path lands.

Dependencies

Verification (local only)

make docker-build-22
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  ./script/ci-local.sh --filter extract

Do not require GitHub Actions.

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions