Skip to content

Language: Compound assignment operators (.=, +=, -=, *=, etc.) #136

Description

@PurHur

Problem

PHPCfg parses Expr_AssignOp_* (e.g. $s .= $x, $n += 1), but lib/Compiler.php::compileExpr() has no lowering — lint reports Expr_AssignOp_ via #136 in UnsupportedRegistry.php.

Templates and counters use .= constantly; for loops (#192) often use += / ++ (#137).

Goal

All common compound assigns used in small web apps: at minimum .=, +=, -=, *=, /=, .=.

Implementation hints

Compiler (lib/Compiler.php)

  • In compileExpr(), handle Op\Expr\AssignOp\Concat, Plus, Minus, etc. (grep AssignOp under vendor/ircmaxell/php-cfg for exact class names).
  • Lower to read-modify-write: load target → apply binary op → store (may emit two TYPE_ASSIGN sequences before a dedicated opcode exists).

VM

  • lib/Runtime.php already wires Optimizer\AssignOp — check if VM opcodes can delegate or mirror that resolver.
  • lib/VM.php: ensure string .= uses string concat, numeric += uses numeric add (no silent cast surprises vs Zend).

JIT (lib/JIT.php)

  • String .=: LLVM call to existing string concat builtin path (same as . binary op).
  • Numeric compound ops: reuse arithmetic LLVM helpers from lib/JIT/Builtin/.

Tests

  • test/compliance/cases/assignop_concat.phpt: $x = 'a'; $x .= 'b'; echo $x;
  • test/compliance/cases/assignop_plus.phpt: $n = 1; $n += 2; echo $n;
  • Register in capability matrix when JIT parity lands.

Acceptance criteria

docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  php bin/vm.php -r '\$s = "Hello"; \$s .= " World"; echo \$s;'
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  php bin/jit.php -r '\$s = "Hello"; \$s .= " World"; echo \$s;'

Both print Hello World. phpc lint clean for scripts using only supported assign ops.

Dependencies

Verification (local / Docker only)

./script/ci-local.sh --filter assignop — no GitHub Actions required.

Links

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