Search by

jbboehr / phpstan-array-merge

jbboehr

PHPStan extension providing an array-merge PHPDoc type for generic array_merge() return types.

Package info

github.com/jbboehr/phpstan-array-merge

Type:phpstan-extension

pkg:composer/jbboehr/phpstan-array-merge

Statistics

Installs: 18

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.2.0 2026-09-06 14:12 UTC

This package is auto-updated.

Last update: 2026-09-06 14:42:29 UTC


README

ci License: AGPL v3 with Romic Exception stability-experimental AI burn

Installation

Requires PHP ^8.1 and PHPStan ^2.0.4.

To use this extension, require it in Composer:

composer require --dev jbboehr/phpstan-array-merge

If you also install phpstan/extension-installer then you're all set!

Manual installation

If you don't want to use phpstan/extension-installer, include extension.neon in your project's PHPStan config:

includes:
    - vendor/jbboehr/phpstan-array-merge/extension.neon

Usage

Have you ever wanted to have a function that performs an array_merge()-like operation but want that generic goodness PHPStan has to offer? WAIT NO MORE!

<?php

class ConstFixture
{
    public const ARRAY = ['foo' => 'bar'];

    /**
     * @template T of array<mixed>
     * @param T $a
     * @phpstan-return array-merge<self::ARRAY, T>
     */
    public static function constMerge(array $a): array
    {
        return array_merge(self::ARRAY, $a);
    }
}

// @akashi-phpstan-error phpstan.dumpType: array{foo: 'bar', baz: 'bat'}
\PHPStan\dumpType(ConstFixture::constMerge(['baz' => 'bat']));

License

This project is licensed under the GNU Affero General Public License version 3 with the Romic Exception (AGPL-3.0-only WITH romic-exception).

The Romic Exception permits linking or combining this extension with other code without that other code becoming subject to the AGPL merely because of the linking or combination. Modifications to the extension remain subject to the AGPL, including its source-availability requirements for modified versions made available to users over a computer network.

See LICENSE.md and the Romic Exception for the complete terms.

Alternative commercial licenses may be available from the Project Steward. Contact John Boehr at jbboehr@gmail.com.