Skip to content

Language: closure use($a, $a) compiles — Zend "Cannot use variable $a twice" (Zend/zend_compile.c) #32153

Description

@PurHur

Category

language · php-src-strict · closures · compile-time fatal

Problem

php-src rejects a closure that lists the same variable twice in use. This compiler accepts use ($a, $a) and runs the body. Distinct from use ($this) (illegal name); this is a duplicate lexical binding.

Repro Zend 8.2+ VM/JIT (2026-08-18 @ 8d228396dc)
$a=1; $f=function() use ($a, $a) { return $a; }; echo "accepted\n"; Fatal: Cannot use variable $a twice (rc=255) accepted (rc=0)

php-src reference

PHP implementation target

  • lib/ closure compile — duplicate use names must compile-fatal with Zend's message including the variable name
  • JIT/AOT share the compile path; no C runtime branches

Repro

./script/docker-exec.sh -- bash -lc 'php bin/vm.php test/repro/maintainer_gap_use_dup.php 2>&1 | head -5'
./script/docker-exec.sh -- bash -lc 'php bin/jit.php test/repro/maintainer_gap_use_dup.php 2>&1 | head -5'

Done when

  • VM and JIT compile-abort with Zend substring Cannot use variable $a twice (rc≠0, no accepted output)
  • Compliance .phpt guard under test/compliance/cases/language/closure_use_duplicate*.phpt
  • php-src-strict; no php-compiler-strict shortcut

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

    area:compilerCompiler / CFG / JITarea:vmVirtual machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions