requireAndMergeArrays.php
Table of Contents
Functions
- requireAndMergeArrays() : array<string|int, mixed>
- Requires multiple PHP files (each returning an array) and merges the results.
Functions
requireAndMergeArrays()
Requires multiple PHP files (each returning an array) and merges the results.
requireAndMergeArrays(array<string|int, mixed> $filePaths[, bool $recursive = true ][, string|null $allowedBase = null ][, int|null $maxBytes = null ]) : array<string|int, mixed>
Each path goes through a defensive validation pipeline before require:
- The path must be a non-empty string.
- It must resolve via realpath() to an existing regular file.
- The file extension must be
.php(case-insensitive). - If
$allowedBaseis provided, the resolved file must be located inside that base directory (defense in depth against path-escape attacks). - If
$maxBytesis provided, the file size must be ≤$maxBytes(defensive cap against parser OOM on extremely large config files).
This protects against arbitrary file inclusion when paths come from untrusted
or semi-trusted sources. Note that even with $allowedBase, callers must still
trust the content of the included files — require executes their PHP code.
Parameters
- $filePaths : array<string|int, mixed>
-
An array of file paths to load.
- $recursive : bool = true
-
Whether to perform a deep (recursive) merge (true) or a simple merge (false).
- $allowedBase : string|null = null
-
Optional absolute directory path. When provided, every file in
$filePathsmust be located inside this directory after canonicalisation. Strongly recommended when paths are not 100% trusted at the call site. - $maxBytes : int|null = null
-
Optional per-file size cap (in bytes). When provided, any file whose size exceeds this limit is rejected before being included, throwing RuntimeException. Default
null(no limit — historical behaviour).
Tags
Return values
array<string|int, mixed> —The merged array.