Skip to content

Stdlib: array_keys() / array_values() — TypeError when argument is not array (ext/standard/array.c parity) #4138

Description

@PurHur

Category

stdlib | runtime

Problem

Same class of Zend mismatch as #4135 (array_key_exists / in_array / array_search): non-array input must raise TypeError, not LogicException.

array_keys() and array_values() currently use build-specific LogicException messages when the array argument is not an array (including objects).

php-src reference

Repro

<?php
$o = new stdClass();
foreach (['array_keys', 'array_values'] as $fn) {
    try {
        $fn($o);
    } catch (TypeError $e) {
        echo "$fn: TypeError\n";
    } catch (Throwable $e) {
        echo "$fn: ", get_class($e), "\n";
    }
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
Runtime array_keys($o)
Zend PHP 8.x TypeError: array_keys(): Argument #1 ($array) must be of type array, stdClass given
This compiler LogicException: ... must be an array in this compiler build

Scope

Files
ext/standard/array_keys.php, array_values.php
JIT helpers if array builtins inline type checks
PHPT under test/compliance/cases/stdlib/

Done when

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

    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