summaryrefslogtreecommitdiff
path: root/vendor/thecodingmachine/safe/deprecated/array.php
blob: f0b3a20b7973bac5ca0d086d378f53eed5476a17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php

namespace Safe;

use Safe\Exceptions\ArrayException;

/**
 * array_flip returns an array in flip
 * order, i.e. keys from array become values and values
 * from array become keys.
 *
 * Note that the values of array need to be valid
 * keys, i.e. they need to be either integer or
 * string. A warning will be emitted if a value has the wrong
 * type, and the key/value pair in question will not be included
 * in the result.
 *
 * If a value has several occurrences, the latest key will be
 * used as its value, and all others will be lost.
 *
 * @param array $array An array of key/value pairs to be flipped.
 * @return array Returns the flipped array on success.
 * @throws ArrayException
 * @deprecated The Safe version of this function is no longer needed in PHP 8.0+
 *
 */
function array_flip(array $array): array
{
    error_clear_last();
    $result = \array_flip($array);
    if ($result === null) {
        throw ArrayException::createFromPhpError();
    }
    return $result;
}

/**
 * This function sorts an array such that array indices maintain their
 * correlation with the array elements they are associated with.
 *
 * This is used mainly when sorting associative arrays where the actual
 * element order is significant.
 *
 * @param array $array The input array.
 * @param int $sort_flags You may modify the behavior of the sort using the optional parameter
 * sort_flags, for details see
 * sort.
 * @throws ArrayException
 * @deprecated The Safe version of this function is no longer needed in PHP 8.0+
 *
 */
function arsort(array &$array, int $sort_flags = SORT_REGULAR): void
{
    error_clear_last();
    $result = \arsort($array, $sort_flags);
    if ($result === false) {
        throw ArrayException::createFromPhpError();
    }
}

/**
 * This function sorts an array such that array indices maintain
 * their correlation with the array elements they are associated
 * with.  This is used mainly when sorting associative arrays where
 * the actual element order is significant.
 *
 * @param array $array The input array.
 * @param int $sort_flags You may modify the behavior of the sort using the optional
 * parameter sort_flags, for details
 * see sort.
 * @throws ArrayException
 * @deprecated The Safe version of this function is no longer needed in PHP 8.0+
 */
function asort(array &$array, int $sort_flags = SORT_REGULAR): void
{
    error_clear_last();
    $result = \asort($array, $sort_flags);
    if ($result === false) {
        throw ArrayException::createFromPhpError();
    }
}

/**
 * Sorts an array by key in reverse order, maintaining key to data
 * correlations. This is useful mainly for associative arrays.
 *
 * @param array $array The input array.
 * @param int $sort_flags You may modify the behavior of the sort using the optional parameter
 * sort_flags, for details see
 * sort.
 * @throws ArrayException
 * @deprecated The Safe version of this function is no longer needed in PHP 8.0+
 *
 */
function krsort(array &$array, int $sort_flags = SORT_REGULAR): void
{
    error_clear_last();
    $result = \krsort($array, $sort_flags);
    if ($result === false) {
        throw ArrayException::createFromPhpError();
    }
}

/**
 * Sorts an array by key, maintaining key to data correlations. This is
 * useful mainly for associative arrays.
 *
 * @param array $array The input array.
 * @param int $sort_flags You may modify the behavior of the sort using the optional
 * parameter sort_flags, for details
 * see sort.
 * @throws ArrayException
 * @deprecated The Safe version of this function is no longer needed in PHP 8.0+
 *
 */
function ksort(array &$array, int $sort_flags = SORT_REGULAR): void
{
    error_clear_last();
    $result = \ksort($array, $sort_flags);
    if ($result === false) {
        throw ArrayException::createFromPhpError();
    }
}

/**
 * This function sorts an array.  Elements will be arranged from
 * lowest to highest when this function has completed.
 *
 * @param array $array The input array.
 * @param int $sort_flags The optional second parameter sort_flags
 * may be used to modify the sorting behavior using these values:
 *
 * Sorting type flags:
 *
 *
 * SORT_REGULAR - compare items normally;
 * the details are described in the comparison operators section
 *
 *
 * SORT_NUMERIC - compare items numerically
 *
 *
 * SORT_STRING - compare items as strings
 *
 *
 *
 * SORT_LOCALE_STRING - compare items as
 * strings, based on the current locale. It uses the locale,
 * which can be changed using setlocale
 *
 *
 *
 *
 * SORT_NATURAL - compare items as strings
 * using "natural ordering" like natsort
 *
 *
 *
 *
 * SORT_FLAG_CASE - can be combined
 * (bitwise OR) with
 * SORT_STRING or
 * SORT_NATURAL to sort strings case-insensitively
 *
 *
 *
 * @throws ArrayException
 * @deprecated The Safe version of this function is no longer needed in PHP 8.0+
 */
function sort(array &$array, int $sort_flags = SORT_REGULAR): void
{
    error_clear_last();
    $result = \sort($array, $sort_flags);
    if ($result === false) {
        throw ArrayException::createFromPhpError();
    }
}

/**
 * This function will sort an array by its values using a user-supplied
 * comparison function.  If the array you wish to sort needs to be sorted by
 * some non-trivial criteria, you should use this function.
 *
 * @param array $array The input array.
 * @param callable $value_compare_func The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
 * Note that before PHP 7.0.0 this integer had to be in the range from -2147483648 to 2147483647.
 *
 * Returning non-integer values from the comparison
 * function, such as float, will result in an internal cast to
 * integer of the callback's return value. So values such as
 * 0.99 and 0.1 will both be cast to an integer value of 0, which will
 * compare such values as equal.
 * @throws ArrayException
 * @deprecated The Safe version of this function is no longer needed in PHP 8.0+
 *
 */
function usort(array &$array, callable $value_compare_func): void
{
    error_clear_last();
    $result = \usort($array, $value_compare_func);
    if ($result === false) {
        throw ArrayException::createFromPhpError();
    }
}

/**
 * Creates an array by using the values from the
 * keys array as keys and the values from the
 * values array as the corresponding values.
 *
 * @param array $keys Array of keys to be used. Illegal values for key will be
 * converted to string.
 * @param array $values Array of values to be used
 * @return array Returns the combined array, FALSE if the number of elements
 * for each array isn't equal.
 * @throws ArrayException
 * @deprecated
 *
 */
function array_combine(array $keys, array $values): array
{
    error_clear_last();
    $result = \array_combine($keys, $values);
    if ($result === false) {
        throw ArrayException::createFromPhpError();
    }
    return $result;
}