2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 | Copyright (c) 1997-2010 The PHP Group |
7 +----------------------------------------------------------------------+
8 | This source file is subject to version 3.01 of the PHP license, |
9 | that is bundled with this package in the file LICENSE, and is |
10 | available through the world-wide-web at the following url: |
11 | http://www.php.net/license/3_01.txt |
12 | If you did not receive a copy of the PHP license and are unable to |
13 | obtain it through the world-wide-web, please send a note to |
14 | license@php.net so we can mail you a copy immediately. |
15 +----------------------------------------------------------------------+
18 #ifndef incl_HPHP_EXT_ARRAY_H_
19 #define incl_HPHP_EXT_ARRAY_H_
21 #include "hphp/runtime/ext/extension.h"
22 #include "hphp/runtime/base/array-util.h"
23 #include "hphp/runtime/base/zend-collator.h"
27 ///////////////////////////////////////////////////////////////////////////////
29 TypedValue
HHVM_FUNCTION(array_chunk
,
32 bool preserve_keys
= false);
33 TypedValue
HHVM_FUNCTION(array_combine
,
35 const Variant
& values
);
36 TypedValue
HHVM_FUNCTION(array_fill_keys
,
38 const Variant
& value
);
39 TypedValue
HHVM_FUNCTION(array_fill
,
42 const Variant
& value
);
43 TypedValue
HHVM_FUNCTION(array_flip
,
44 const Variant
& trans
);
45 bool HHVM_FUNCTION(array_key_exists
,
47 const Variant
& search
);
48 bool HHVM_FUNCTION(key_exists
,
50 const Variant
& search
);
51 TypedValue
HHVM_FUNCTION(array_keys
,
53 TypedValue
HHVM_FUNCTION(array_map
,
54 const Variant
& callback
,
56 const Array
& _argv
= null_array
);
57 TypedValue
HHVM_FUNCTION(array_replace_recursive
,
58 const Variant
& array1
,
59 const Variant
& array2
= uninit_variant
,
60 const Array
& args
= null_array
);
61 TypedValue
HHVM_FUNCTION(array_replace
,
62 const Variant
& array1
,
63 const Variant
& array2
= uninit_variant
,
64 const Array
& args
= null_array
);
65 TypedValue
HHVM_FUNCTION(array_pad
,
68 const Variant
& pad_value
);
69 TypedValue
HHVM_FUNCTION(array_product
,
70 const Variant
& array
);
71 TypedValue
HHVM_FUNCTION(array_push
,
74 const Array
& args
= null_array
);
75 TypedValue
HHVM_FUNCTION(array_rand
,
78 TypedValue
HHVM_FUNCTION(array_search
,
79 const Variant
& needle
,
80 const Variant
& haystack
,
82 TypedValue
HHVM_FUNCTION(array_shift
,
84 TypedValue
HHVM_FUNCTION(array_splice
,
87 const Variant
& length
= uninit_variant
,
88 const Variant
& replacement
= uninit_variant
);
89 TypedValue
HHVM_FUNCTION(array_sum
,
90 const Variant
& array
);
91 TypedValue
HHVM_FUNCTION(array_unique
,
94 TypedValue
HHVM_FUNCTION(array_unshift
,
97 const Array
& args
= null_array
);
98 TypedValue
HHVM_FUNCTION(array_values
,
99 const Variant
& input
);
100 bool HHVM_FUNCTION(shuffle
,
102 int64_t HHVM_FUNCTION(count
,
105 int64_t HHVM_FUNCTION(sizeof,
107 Variant
HHVM_FUNCTION(each
,
109 Variant
HHVM_FUNCTION(current
,
110 const Variant
& array
);
111 Variant
HHVM_FUNCTION(key
,
112 const Variant
& array
);
113 Variant
HHVM_FUNCTION(next
,
115 Variant
HHVM_FUNCTION(prev
,
117 Variant
HHVM_FUNCTION(reset
,
119 Variant
HHVM_FUNCTION(end
,
121 bool HHVM_FUNCTION(in_array
,
122 const Variant
& needle
,
123 const Variant
& haystack
,
124 bool strict
= false);
125 TypedValue
HHVM_FUNCTION(range
,
128 const Variant
& step
= 1);
129 TypedValue
HHVM_FUNCTION(array_diff
,
130 const Variant
& container1
,
131 const Variant
& container2
,
132 const Array
& args
= null_array
);
133 TypedValue
HHVM_FUNCTION(array_diff_key
,
134 const Variant
& container1
,
135 const Variant
& container2
,
136 const Array
& args
= null_array
);
137 TypedValue
HHVM_FUNCTION(array_udiff
,
138 const Variant
& array1
,
139 const Variant
& array2
,
140 const Variant
& data_compare_func
,
141 const Array
& args
= null_array
);
142 TypedValue
HHVM_FUNCTION(array_diff_assoc
,
143 const Variant
& array1
,
144 const Variant
& array2
,
145 const Array
& args
= null_array
);
146 TypedValue
HHVM_FUNCTION(array_diff_uassoc
,
147 const Variant
& array1
,
148 const Variant
& array2
,
149 const Variant
& key_compare_func
,
150 const Array
& args
= null_array
);
151 TypedValue
HHVM_FUNCTION(array_udiff_assoc
,
152 const Variant
& array1
,
153 const Variant
& array2
,
154 const Variant
& data_compare_func
,
155 const Array
& args
= null_array
);
156 TypedValue
HHVM_FUNCTION(array_udiff_uassoc
,
157 const Variant
& array1
,
158 const Variant
& array2
,
159 const Variant
& data_compare_func
,
160 const Variant
& key_compare_func
,
161 const Array
& args
= null_array
);
162 TypedValue
HHVM_FUNCTION(array_diff_ukey
,
163 const Variant
& array1
,
164 const Variant
& array2
,
165 const Variant
& key_compare_func
,
166 const Array
& args
= null_array
);
167 TypedValue
HHVM_FUNCTION(array_intersect
,
168 const Variant
& container1
,
169 const Variant
& container2
,
170 const Array
& args
= null_array
);
171 TypedValue
HHVM_FUNCTION(array_intersect_key
,
172 const Variant
& container1
,
173 const Variant
& container2
,
174 const Array
& args
= null_array
);
175 TypedValue
HHVM_FUNCTION(array_uintersect
,
176 const Variant
& array1
,
177 const Variant
& array2
,
178 const Variant
& data_compare_func
,
179 const Array
& args
= null_array
);
180 TypedValue
HHVM_FUNCTION(array_intersect_assoc
,
181 const Variant
& array1
,
182 const Variant
& array2
,
183 const Array
& args
= null_array
);
184 TypedValue
HHVM_FUNCTION(array_intersect_uassoc
,
185 const Variant
& array1
,
186 const Variant
& array2
,
187 const Variant
& key_compare_func
,
188 const Array
& args
= null_array
);
189 TypedValue
HHVM_FUNCTION(array_uintersect_assoc
,
190 const Variant
& array1
,
191 const Variant
& array2
,
192 const Variant
& data_compare_func
,
193 const Array
& args
= null_array
);
194 TypedValue
HHVM_FUNCTION(array_uintersect_uassoc
,
195 const Variant
& array1
,
196 const Variant
& array2
,
197 const Variant
& data_compare_func
,
198 const Variant
& key_compare_func
,
199 const Array
& args
= null_array
);
200 TypedValue
HHVM_FUNCTION(array_intersect_ukey
,
201 const Variant
& array1
,
202 const Variant
& array2
,
203 const Variant
& key_compare_func
,
204 const Array
& args
= null_array
);
205 bool HHVM_FUNCTION(sort
,
208 bool HHVM_FUNCTION(rsort
,
211 bool HHVM_FUNCTION(asort
,
214 bool HHVM_FUNCTION(arsort
,
217 bool HHVM_FUNCTION(ksort
,
220 bool HHVM_FUNCTION(krsort
,
223 bool HHVM_FUNCTION(usort
,
225 const Variant
& cmp_function
);
226 bool HHVM_FUNCTION(uasort
,
228 const Variant
& cmp_function
);
229 bool HHVM_FUNCTION(uksort
,
231 const Variant
& cmp_function
);
232 bool HHVM_FUNCTION(natsort
,
234 bool HHVM_FUNCTION(natcasesort
,
236 String
HHVM_FUNCTION(i18n_loc_get_default
);
237 bool HHVM_FUNCTION(i18n_loc_set_default
,
238 const String
& locale
);
239 bool HHVM_FUNCTION(i18n_loc_set_attribute
,
242 bool HHVM_FUNCTION(i18n_loc_set_strength
,
244 Variant
HHVM_FUNCTION(i18n_loc_get_error_code
);
245 TypedValue
HHVM_FUNCTION(hphp_array_idx
,
246 const Variant
& search
,
250 ///////////////////////////////////////////////////////////////////////////////
252 inline int64_t countHelper(TypedValue tv
) {
253 return HHVM_FN(count
)(tvAsVariant(&tv
));
256 ///////////////////////////////////////////////////////////////////////////////
258 #define getCheckedArrayRet(input, fail) \
259 auto const cell_##input = static_cast<const Variant&>(input).toCell(); \
260 if (UNLIKELY(!isArrayLikeType(cell_##input->m_type) && \
261 !isClsMethType(cell_##input->m_type))) { \
262 throw_expected_array_exception(); \
265 if (isClsMethType(cell_##input->m_type)) raiseClsMethToVecWarningHelper(); \
266 ArrNR arrNR_##input{isClsMethType(cell_##input->m_type) ? \
267 clsMethToVecHelper(cell_##input->m_data.pclsmeth).detach() : \
268 cell_##input->m_data.parr}; \
269 const Array& arr_##input = arrNR_##input.asArray();
271 #define getCheckedContainer(input) \
272 if (UNLIKELY(!isContainer(input) && !input.isClsMeth())) { \
273 throw_expected_array_or_collection_exception(); \
274 return make_tv<KindOfNull>(); \
276 Variant var_##input(input); \
277 tvCastToArrayInPlace<TypedValue*, IntishCast::Cast>( \
278 var_##input.asTypedValue() \
280 assertx(var_##input.isArray()); \
281 auto arr_##input = var_##input.toArray<IntishCast::Cast>();
283 #define getCheckedArray(input) \
284 getCheckedArrayRet(input, make_tv<KindOfNull>())
285 #define getCheckedArrayVariant(input) \
286 getCheckedArrayRet(input, init_null())
290 #endif // incl_HPHP_EXT_ARRAY_H_