Skip to content

Regression: glob() enum pattern operand — silent empty array not TypeError (re-#5732, dir.c) #8781

Description

@PurHur

Category

stdlib | php-src-strict

Problem

#5732 landed but regressed: glob() with an enum case $pattern returns an empty array instead of throwing TypeError. Zend rejects non-string patterns before filesystem lookup.

php-src reference

Repro

test/repro-maintainer/parity_glob_enum_pattern.php:

<?php
declare(strict_types=1);
enum E { case A; }
enum Es: string { case P = '*.txt'; }
foreach ([E::A, Es::P] as $pattern) {
    try {
        var_export(glob($pattern));
        echo "\nuncaught\n";
    } catch (Throwable $e) {
        echo get_class($e), ': ', $e->getMessage(), "\n";
    }
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_glob_enum_pattern.php
php bin/vm.php test/repro-maintainer/parity_glob_enum_pattern.php'
Runtime Result
Zend TypeError: glob(): Argument #1 ($pattern) must be of type string, E given (and same for Es)
VM today array () + uncaught (no exception)

Scope (this repo)

Path Work
ext/standard/glob.php Reject enum operands via VmString::requireStringBuiltinArg (not coerce / not empty-array fallback)
lib/JIT/Builtin/*Glob* Mirror strict string check when JIT lowering exists
Tests test/compliance/cases/stdlib/glob_enum_pattern.phpt

PHP-in-PHP: fix operand guard in ext/standard; do not add C branches in runtime/.

Done when

  • Repro prints TypeError for both pure and backed enum cases (no uncaught)
  • Valid string patterns still return matches / empty array per Zend
  • JIT/AOT parity when glob JIT exists (or matrix notes VM-only deferral)
  • ./script/ci-fast.sh --filter glob_enum green

Related

#5732 (closed) · #7405 (php-in-php glob vec) · #1492

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions