L
L
LittleFatNinja2015-10-05 17:06:48
PHP
LittleFatNinja, 2015-10-05 17:06:48

Is the is_array function reliable?

Is php is_array function safe?
that is, is there a guarantee that if NOT an array arrives, it will return FALSE for any?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2015-10-05
@LittleFatNinja

On the example of PHP5.6.14
ext/standard/type.c PHP_FUNCTION(is_array) calls php_is_type (the function is defined in the same place, just above)
It checks for equality Z_TYPE_PP(arg).
Z_TYPE_PP, respectively, macro from Zend/zend_operators.h

#define Z_TYPE(zval)		(zval).type
#define Z_TYPE_P(zval_p)	Z_TYPE(*zval_p)
#define Z_TYPE_PP(zval_pp)	Z_TYPE(**zval_pp)

As you can see, direct access to the type field of the zval structure base for zend. Well, it cannot lie, either IS_ARRAY and is_array will give true or something else and the result will be false.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question