Skip to content

feat(reflection): optimizer-aware frame-variable presence/enumeration API on ExecutionData #240

Closed

Description

@lisachenko

Summary

With opcache active, the optimizer (SCCP + dead-code elimination + CV compaction) legitimately removes and renumbers compiled-variable slots. Frame introspection then sees the optimized truth: a variable that exists in the source may have no CV slot at runtime, and ExecutionData::getLocalVariable() throws OutOfBoundsException for it.

Found by running the full suite with opcache.enable_cli=1 in the runner: tests/System/ExecutionDataTest::testGetLocalVariableObservesUndefSlot (never-assigned CV dropped after range inference proves its branch dead) and ::testGetLocalVariablesOfParentFrame (a marker CV removed by SCCP + DCE) fail; both pass with opcache.optimization_level=0. Identical on the 8.4 and master lines; deterministic.

Agreed design (discussed with the maintainer)

Hybrid stance:

  1. Document the optimizer reality — introspection reports the optimized op_array truthfully; instrumentation scenarios that must see every source variable should run with opcache.optimization_level=0 (docs/self-debugging.md).
  2. Keep the throw on access to a missing variable (getLocalVariable() keeps its OutOfBoundsException).
  3. Add presence/enumeration API so clients can probe before access, following the existing naming family:
    • ExecutionData::hasLocalVariable(string $variableName): bool
    • promote the existing private ExecutionData::getLocalVariableNames() (slot-keyed array<int, string>) to public.

Tests adapt to be branch-aware: probe presence first; when the slot is present (default opcache-off CI) the original strict assertions run unchanged, when absent (opcache-active runner) the throw / empty-shape contract is asserted instead.

Applies to branch 8.4 first, cascades to master.

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

    enhancementNew feature or requestopcacheIssue is related to opcache integration. Either doesn't work well or behaves incorrect.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions