From ddde872560a51cf8916c054b19e0b3f0f537ac59 Mon Sep 17 00:00:00 2001 From: Kirill Nesmeyanov Date: Sun, 17 May 2026 19:37:52 +0300 Subject: [PATCH] Fix function redeclare fatal error Closes https://github.com/php-ds/polyfill/issues/113 --- src/functions.php | 56 +++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/functions.php b/src/functions.php index 650b32e..5e56ae8 100644 --- a/src/functions.php +++ b/src/functions.php @@ -1,34 +1,42 @@ value pairs. - */ -function map(iterable $values = []): Map -{ - return new Map($values); +if (!function_exists('Ds\\map')) { + /** + * Create a new Map from an iterable of key => value pairs. + */ + function map(iterable $values = []): Map + { + return new Map($values); + } } -/** - * Create a new Set from an iterable. - */ -function set(iterable $values = []): Set -{ - return new Set($values); +if (!function_exists('Ds\\set')) { + /** + * Create a new Set from an iterable. + */ + function set(iterable $values = []): Set + { + return new Set($values); + } } -/** - * Create a new Heap from an iterable with optional comparator. - */ -function heap(iterable $values = [], ?callable $comparator = null): Heap -{ - return new Heap($values, $comparator); +if (!function_exists('Ds\\heap')) { + /** + * Create a new Heap from an iterable with optional comparator. + */ + function heap(iterable $values = [], ?callable $comparator = null): Heap + { + return new Heap($values, $comparator); + } }