Skip to content

array_combine() converts boolean false keys to empty strings instead of integer keys #24254

Description

@arshidkv12

Description

array_combine() converts a boolean false key to an empty string ("") instead of integer key 0, unlike normal PHP array-key conversion behavior.

Code to reproduce

<?php
var_dump(array_combine([true, false], ['true', 'false']));

Actual output

array(2) {
  [1]=>
  string(4) "true"
  [""]=>
  string(5) "false"
}

Expected output

array(2) {
  [1]=>
  string(4) "true"
  [0]=>
  string(5) "false"
}

Affected versions: PHP 8.4.x, PHP 8.5.x, PHP 8.6.x, and PHP 8.7.x

Additional information

Direct array construction converts boolean keys to integers:

var_dump([true => 'true', false => 'false']);

This suggests that array_combine() may be converting boolean keys to strings rather than applying the usual PHP array-key conversion rules.

PHP Version

PHP 8.4.26-dev (cli) (built: Oct 11 2026 12:44:08) (NTS DEBUG)
Copyright (c) The PHP Group
Zend Engine v4.4.26-dev, Copyright (c) Zend Technologies

Operating System

No response

Activity

  1. ndossche commented on Oct 11, 2026

    @ndossche
    Member

    Actually, reading the documentation:

    Array of keys to be used. Illegal values for key will be converted to string.

    So the behaviour seems correct. If you want a change in behaviour, then this has to go through the maling list and to master first.

  2. arshidkv12 commented on Oct 11, 2026

    @arshidkv12
    ContributorAuthor

    Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions