Skip to content

Language: Double-quoted string interpolation ($var, {$obj->x}) #261

@PurHur

Description

@PurHur

Problem

PHP web templates and APIs rely on double-quoted strings with embedded variables:

echo "Hello, $name";
echo "Route: {$route}";

If php-cfg emits Scalar_Encapsed / encapsed string parts that lib/Compiler.php does not lower, compilation fails with Unsupported expression or wrong output. Concatenation ('Hello ' . $name) works but is verbose and common in real apps (#67, templates in #246).

Goal

Support standard double-quoted interpolation in VM, JIT, and AOT for:

  • Simple variables: "$name"
  • Complex expressions in braces: "{$user['id']}", "{$obj->method()}" (v1 may limit to variables/array offsets)

Scope

  • Audit php-cfg output for encapsed strings in PHPCfg\Operand
  • Lower to string concat chain or dedicated opcode sequence in Compiler::compileExpr
  • VM: evaluate parts left-to-right, concat
  • JIT: LLVM concat of string values (reuse JitStringConcat / TYPE_CONCAT)
  • PHPT: test/compliance/cases/language/encapsed_string.phpt
  • Register in lib/Lint/UnsupportedRegistry.php until implemented (Lint: Register Phase-2 blockers in UnsupportedRegistry (ternary, .=, break) #258)

Acceptance criteria

$name = 'Dev';
echo "Hello, $name\n";

Identical output in bin/vm.php and bin/jit.php.

Verification (local only)

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

No GitHub Actions required.

Dependencies

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions