Skip to content

Stdlib: array_fill_keys() inline [new …] literal — operand lowering passes object as $keys (ext/standard/array.c) #10849

Description

@PurHur

Summary

array_fill_keys([new stdClass()], 1) must fail with Error: Object of class stdClass could not be converted to string (object inside the keys array). VM mis-lowers the inline array literal and reports TypeError: … Argument #1 ($keys) must be of type array, stdClass given — as if the new expression were the $keys operand itself.

Using a variable works: array_fill_keys([$o], 1) reaches the correct Error.

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_gap_array_fill_keys_inline_new.php
php bin/vm.php test/repro/maintainer_gap_array_fill_keys_inline_new.php'
Call Zend PHP 8.2 VM today
array_fill_keys([new stdClass()], 1) Error (object to string) TypeError on $keys type
array_fill_keys([$o], 1) Error Error

var_export([new stdClass()]) alone is fine — bug is call-site operand lowering, same family as #10093/#10775 inline literal gaps.

php-src reference

Implementation (PHP-in-PHP)

Done when (php-src-strict)

  • Inline repro throws Error matching Zend message
  • Variable form still works
  • No regression on array_combine([new stdClass()], [1]) (already correct)

Verification

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

Related: #10093, #10775, #8779, #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