Implement HH\is_late_init_prop_init and HH\is_late_init_sprop_init
[hiphop-php.git] / hphp / runtime / ext / std / ext_std_variable.php
blob1ccf04f8fd8ee4b77702c2b4865d12f001814dca
1 <?hh
3 namespace {
4 /* Finds whether the given variable is a boolean.
5 */
6 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
7 function is_bool(<<__MaybeMutable>> mixed $var): bool;
9 /* Finds whether the type of the given variable is integer. To test if a
10 * variable is a number or a numeric string (such as form input, which is
11 * always a string), you must use is_numeric().
13 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
14 function is_int(<<__MaybeMutable>> mixed $var): bool;
16 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
17 function is_integer(<<__MaybeMutable>> mixed $var): bool;
19 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
20 function is_long(<<__MaybeMutable>> mixed $var): bool;
22 /* Finds whether the type of the given variable is float. To test if a
23 * variable is a number or a numeric string (such as form input, which is
24 * always a string), you must use is_numeric().
26 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
27 function is_float(<<__MaybeMutable>> mixed $var): bool;
29 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
30 function is_double(<<__MaybeMutable>> mixed $var): bool;
32 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
33 function is_real(<<__MaybeMutable>> mixed $var): bool;
35 /* Finds whether the given variable is numeric. Numeric strings consist of
36 * optional sign, any number of digits, optional decimal part and optional
37 * exponential part. Thus +0123.45e6 is a valid numeric value. Hexadecimal
38 * notation (0xFF) is allowed too but only without sign, decimal and
39 * exponential part.
41 <<__IsFoldable, __Native, __Rx>>
42 function is_numeric(<<__MaybeMutable>> mixed $var): bool;
44 /* Finds whether the type given variable is string.
46 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
47 function is_string(<<__MaybeMutable>> mixed $var): bool;
49 /* Finds whether the given variable is a scalar. Scalar variables are those
50 * containing an integer, float, string or boolean. Types array, object and
51 * resource are not scalar. is_scalar() does not consider resource type
52 * values to be scalar as resources are abstract datatypes which are currently
53 * based on integers. This implementation detail should not be relied upon, as
54 * it may change.
56 <<__IsFoldable, __Native, __Rx>>
57 function is_scalar(<<__MaybeMutable>> mixed $var): bool;
59 /* Finds whether the given variable is an array.
61 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
62 function is_array(<<__MaybeMutable>> mixed $var): bool;
64 /* Finds whether the given variable is an object.
66 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
67 function is_object(<<__MaybeMutable>> mixed $var): bool;
69 /* Finds whether the given variable is a resource.
71 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
72 function is_resource(<<__MaybeMutable>> mixed $var): bool;
74 /* Finds whether the given variable is NULL.
76 <<__IsFoldable, __Native, __ParamCoerceModeFalse, __Rx>>
77 function is_null(<<__MaybeMutable>> mixed $var): bool;
79 /* Returns the type of the PHP variable var. Warning Never use gettype() to
80 * test for a certain type, since the returned string may be subject to change
81 * in a future version. In addition, it is slow too, as it involves string
82 * comparison. Instead, use the is_* functions.
84 <<__IsFoldable, __Native, __Rx>>
85 function gettype(<<__MaybeMutable>> mixed $v): string;
87 /* This function gets the type of the given resource.
89 <<__IsFoldable, __Native, __Rx>>
90 function get_resource_type(<<__MaybeMutable>> resource $handle): string;
92 <<__IsFoldable, __Native, __Rx>>
93 function boolval(mixed $var): bool;
95 /* Returns the integer value of var, using the specified base for the
96 * conversion (the default is base 10). intval() should not be used on
97 * objects, as doing so will emit an E_NOTICE level error and return 1.
99 <<__IsFoldable, __Native, __Rx>>
100 function intval(mixed $var,
101 int $base = 10): int;
103 /* Gets the float value of var.
105 <<__IsFoldable, __Native, __Rx>>
106 function floatval(mixed $var): float;
108 <<__IsFoldable, __Native, __Rx>>
109 function doubleval(mixed $var): float;
111 <<__IsFoldable, __Native, __Rx>>
112 function strval(mixed $var): string;
114 /* Set the type of variable var to type.
116 <<__Native>>
117 function settype(mixed &$var,
118 string $type): bool;
120 /* print_r() displays information about a variable in a way that's readable by
121 * humans. print_r(), var_dump() and var_export() will also show protected
122 * and private properties of objects with PHP 5. Static class members will not
123 * be shown. Remember that print_r() will move the array pointer to the end.
124 * Use reset() to bring it back to beginning.
126 <<__Native>>
127 function print_r(mixed $expression,
128 bool $ret = false): mixed;
130 <<__Native>>
131 function var_export(mixed $expression,
132 bool $ret = false): mixed;
134 /* Dumps information about a variable
136 * This function displays structured information about one or more expressions
137 * that includes its type and value. Arrays and objects are explored
138 * recursively with values indented to show structure.
140 * @param mixed $var - Variable to dump
142 /* Dumps a string representation of an internal zend value to output.
144 <<__Native("NoFCallBuiltin")>>
145 function var_dump(mixed $arg1, ...$argv): void;
147 <<__Native>>
148 function debug_zval_dump(mixed $variable): void;
150 /* Generates a storable representation of a value This is useful for storing
151 * or passing PHP values around without losing their type and structure. To
152 * make the serialized string into a PHP value again, use unserialize().
154 * Calls to serialize are foldable because only objects can invoke user-defined
155 * code.
157 <<__IsFoldable, __Native>>
158 function serialize(mixed $value): string;
160 <<__Native, __ParamCoerceModeFalse>>
161 function unserialize(string $str,
162 array $options = []): mixed;
164 /* This function returns a multidimensional array containing a list of all
165 * defined variables, be they environment, server or user-defined
166 * variables, within the scope in which get_defined_vars() is called.
168 <<__Native("ReadsCallerFrame")>>
169 function get_defined_vars(): array;
171 /* Imports GET/POST/Cookie variables into the global scope. It is useful if
172 * you disabled register_globals, but would like to see some variables in the
173 * global scope.
175 function import_request_variables(string $types,
176 string $prefix = ""): bool {
177 throw new Exception("It is bad coding practice to remove scoping of ".
178 "variables just to achieve coding convenience, ".
179 "esp. in a language that encourages global ".
180 "variables. This is possible to implement ".
181 "though, by declaring those global variables ".
182 "beforehand and assign with scoped ones when ".
183 "this function is called.");
187 * Parses str as if it were the query string passed via a URL and sets $arr.
189 * To get the current QUERY_STRING, you may use the variable
190 * $_SERVER['QUERY_STRING']. Also, you may want to read the section on
191 * variables from external sources.
193 * The magic_quotes_gpc setting affects the output of this function, as
194 * parse_str() uses the same mechanism that PHP uses to populate the $_GET,
195 * $_POST, etc. variables.
197 <<__Native>>
198 function parse_str(string $str, mixed &$arr): void;
202 namespace HH {
204 /* Finds whether the given variable is a vec.
206 <<__Native, __ParamCoerceModeFalse, __IsFoldable, __Rx>>
207 function is_vec(<<__MaybeMutable>> mixed $var): bool;
209 /* Finds whether the given variable is a dict.
211 <<__Native, __ParamCoerceModeFalse, __IsFoldable, __Rx>>
212 function is_dict(<<__MaybeMutable>> mixed $var): bool;
214 /* Finds whether the given variable is a keyset.
216 <<__Native, __ParamCoerceModeFalse, __IsFoldable, __Rx>>
217 function is_keyset(<<__MaybeMutable>> mixed $var): bool;
219 <<__Native, __ParamCoerceModeFalse, __IsFoldable, __Rx>>
220 function is_varray(<<__MaybeMutable>> mixed $var): bool;
222 <<__Native, __ParamCoerceModeFalse, __IsFoldable, __Rx>>
223 function is_darray(<<__MaybeMutable>> mixed $var): bool;
225 <<__Native, __ParamCoerceModeFalse, __IsFoldable, __Rx>>
226 function is_any_array(<<__MaybeMutable>> mixed $var): bool;
229 * Check if the input is an array-like containing only integer keys running
230 * from 0 to N-1, in that order.
232 <<__Native, __ParamCoerceModeFalse, __IsFoldable, __Rx>>
233 function is_list_like(<<__MaybeMutable>> arraylike $var): bool;
236 * Behaves like serialize() but takes an optional set of options.
238 * Options:
240 * warnOnHackArrays - If true, emit a Hack array compat notice if serializing a
241 * Hack array
242 * warnOnPHPArrays - If true, emit a Hack array compat notice if serializing a
243 * PHP array
244 * forcePHPArrays - If true, serialize all Hack arrays as PHP arrays
246 <<__Native, __IsFoldable>>
247 function serialize_with_options(mixed $value, dict $options = dict[]): string;
250 * This function returns an array of an object's properties in the same manner
251 * as casting the object to an array.
253 <<__Native>>
254 function object_prop_array(object $obj): array;
257 * Return true if the <<__LateInit>> property (with name $prop) on the given
258 * object is initialized to a value (and therefore will not throw when
259 * accessed). Throws InvalidArgumentException if the property does not exist
260 * or is inaccessible in the current context.
262 <<__Native>>
263 function is_late_init_prop_init(object $obj, string $prop): bool;
266 * Return true if the <<__LateInit>> static property (with name $prop) on the
267 * class given by $cls is initialized to a value (and therefore will not throw
268 * when accessed). Throws InvalidArgumentException if $cls is not a valid
269 * classname, if the static property does not exist, or if the static property
270 * is inaccessible in the current context.
272 <<__Native>>
273 function is_late_init_sprop_init(string $cls, string $prop): bool;
276 namespace HH\Lib\_Private\Native {
278 * container intrinsic for HH\traversable
280 <<__Native, __IsFoldable, __Rx, __AtMostRxAsArgs>>
281 function first(
282 <<__OnlyRxIfImpl(\HH\Rx\Traversable::class), __MaybeMutable>>
283 mixed $iterable
284 ): mixed;
286 <<__Native, __IsFoldable, __Rx, __AtMostRxAsArgs>>
287 function first_key(
288 <<__OnlyRxIfImpl(\HH\Rx\Traversable::class), __MaybeMutable>>
289 mixed $iterable
290 ): mixed;
292 <<__Native, __IsFoldable, __Rx, __AtMostRxAsArgs>>
293 function last(
294 <<__OnlyRxIfImpl(\HH\Rx\Traversable::class), __MaybeMutable>>
295 mixed $iterable
296 ): mixed;
298 <<__Native, __IsFoldable, __Rx, __AtMostRxAsArgs>>
299 function last_key(
300 <<__OnlyRxIfImpl(\HH\Rx\Traversable::class), __MaybeMutable>>
301 mixed $iterable
302 ): mixed;