jbboehr / phpstan-array-merge
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
Requires
- php: ^8.1
- phpstan/phpstan: ^2.0.4
Requires (Dev)
- composer-runtime-api: *
- jbboehr/akashi: ^0.2
- phpstan/phpstan-phpunit: ^2.0.6
- phpstan/phpstan-strict-rules: ^2.0.4
- phpunit/phpunit: ^10.5.62 || ^11.5.50
- slevomat/coding-standard: ^8.18
- squizlabs/php_codesniffer: ^3.13
- symfony/var-dumper: *
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-06 14:42:29 UTC
README
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.