Skip to content

Stdlib: token_get_all() null byte after $ — T_VARIABLE not literal dollar + T_BAD_CHARACTER (ext/tokenizer/tokenizer.c) #13896

Closed

Description

@PurHur

Category

stdlib · php-src-strict · lexer/tokenizer parity

Problem

For source <?php $\0 = 1;, token_get_all() must lex the bytes after <?php as a literal '$' token followed by T_BAD_CHARACTER for the embedded NUL. This compiler’s VM returns T_VARIABLE with value '$' plus T_BAD_CHARACTER, diverging from Zend’s token stream.

Downstream tools that diff token streams against php-src (static analysis, highlight pipelines) see a false variable name.

php-src reference

Repro (verified 2026-06-30)

test/repro/maintainer_gap_token_get_all_null_byte.php

php test/repro/maintainer_gap_token_get_all_null_byte.php
php bin/vm.php test/repro/maintainer_gap_token_get_all_null_byte.php
Check Zend VM
Second token after T_OPEN_TAG literal '$' T_VARIABLE ('$')
Third token T_BAD_CHARACTER (NUL) T_BAD_CHARACTER (NUL)
Exit 0 1

Scope (PHP-in-PHP first)

Layer Path
VM ext/tokenizer/ scanner / token_get_all() lowering
Compiler reuse shared lexer paths if compile-time token_get_all shares scanner

Avoid new C in runtime/ unless thin ABI for scanner hook is unavoidable.

Done when (php-src-strict)

  • Token stream matches Zend for NUL-after-$ sample
  • Repro exits 0 on VM
  • No regressions on normal T_VARIABLE names

Verification

php bin/vm.php test/repro/maintainer_gap_token_get_all_null_byte.php

Links

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 30, 2026
  2. PurHur commented on Jun 30, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — batch (issues #13896, #4710)

  3. PurHur commented on Jun 30, 2026

    @PurHur
    OwnerAuthor

    Merged via #13908. token_get_all('<?php $\0 = 1;') now matches Zend: literal '$' + T_BAD_CHARACTER. Verified VM + AOT lint + unit tests.

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:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsstdlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions