Skip to content

Stdlib: array_fill_keys() resource keys — must stringify 'Resource id #N' not Error (ext/standard/array.c) #10847

Description

@PurHur

Summary

When array_fill_keys() receives a resource in the keys list, Zend coerces it to the string "Resource id #N" (with E_WARNING in some builds) and builds the result hash. VM throws Error: Object of class Resource could not be converted to string instead.

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_gap_array_fill_keys_resource.php
php bin/vm.php test/repro/maintainer_gap_array_fill_keys_resource.php'
Call Zend PHP 8.2 VM today
array_fill_keys([$stream], 1) array('Resource id #5' => 1) Error

php-src reference

Implementation (PHP-in-PHP)

  • ext/standard/VmArray.phparray_fill_keys key coercion: resources → "Resource id #" + id (match VmResource / print_r formatting)
  • Share helper with other builtins that accept hash keys (array_combine already errors correctly on objects — only resource path differs)
  • No new C runtime

Done when (php-src-strict)

  • Repro returns array('Resource id #N' => 1) on VM
  • Object keys still Error (not regressed)
  • JIT/AOT agree when in scope

Verification

./script/docker-exec.sh -- php bin/vm.php test/repro/maintainer_gap_array_fill_keys_resource.php

Related: #8779 (enum keys), #1492

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