. Updated bundled libsqlite to 3.22.0. (cmb)
- Standard:
+ . Added is_countable() function. (Gabriel Caruso)
. Fixed bug #75916 (DNS_CAA record results contain garbage). (Mike,
Philip Sharp)
. Fixed unserialize(), to disable creation of unsupported data structures
URestrictionLevel under
http://icu-project.org/apiref/icu4c/uspoof_8h.html
-SPL:
- . Added spl_object_id().
+Standard:
+ . Added is_countable() function, to check whether a value may be passed to
+ count().
+ (RFC: https://wiki.php.net/rfc/is-countable)
========================================
7. New Classes and Interfaces
}
/* }}} */
+ZEND_API zend_bool zend_is_countable(zval *countable) /* {{{ */
+{
+ switch (Z_TYPE_P(countable)) {
+ case IS_ARRAY:
+ return 1;
+ case IS_OBJECT:
+ if (Z_OBJ_HT_P(countable)->count_elements) {
+ return 1;
+ }
+
+ return instanceof_function(Z_OBJCE_P(countable), zend_ce_countable);
+ default:
+ return 0;
+ }
+}
+/* }}} */
+
/*
* Local variables:
* tab-width: 4
ZEND_API zend_bool zend_is_iterable(zval *iterable);
+ZEND_API zend_bool zend_is_countable(zval *countable);
+
#define add_method(arg, key, method) add_assoc_function((arg), (key), (method))
ZEND_API ZEND_FUNCTION(display_disabled_function);
F0("is_object", MAY_BE_FALSE | MAY_BE_TRUE), // TODO: inline with support for incomplete class
F0("is_scalar", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
F0("is_callable", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
+ F0("is_countable", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_TRUE),
F0("pclose", MAY_BE_FALSE | MAY_BE_LONG),
F1("popen", MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_RESOURCE),
F0("readfile", MAY_BE_FALSE | MAY_BE_LONG),
ZEND_BEGIN_ARG_INFO_EX(arginfo_is_iterable, 0, 0, 1)
ZEND_ARG_INFO(0, var)
ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_is_countable, 0)
+ ZEND_ARG_INFO(0, var)
+ZEND_END_ARG_INFO()
/* }}} */
/* {{{ uniqid.c */
#ifdef HAVE_GETTIMEOFDAY
PHP_FE(is_scalar, arginfo_is_scalar)
PHP_FE(is_callable, arginfo_is_callable)
PHP_FE(is_iterable, arginfo_is_iterable)
+ PHP_FE(is_countable, arginfo_is_countable)
/* functions from file.c */
PHP_FE(pclose, arginfo_pclose)
PHP_FUNCTION(is_scalar);
PHP_FUNCTION(is_callable);
PHP_FUNCTION(is_iterable);
+PHP_FUNCTION(is_countable);
#endif
--- /dev/null
+--TEST--
+Test is_countable() function
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--FILE--
+<?php
+var_dump(is_countable(new class extends ArrayIterator {}));
+var_dump(is_countable((array) new stdClass()));
+var_dump(is_countable(new class implements Countable {
+ public function count()
+ {
+ return count(1, 'foo');
+ }
+}));
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
--- /dev/null
+--TEST--
+Test is_countable() function
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--FILE--
+<?php
+var_dump(is_countable([1, 2, 3]));
+var_dump(is_countable((array) 1));
+var_dump(is_countable((object) ['foo', 'bar', 'baz']));
+var_dump(is_countable());
+
+$foo = ['', []];
+
+if (is_countable($foo)) {
+ var_dump(count($foo));
+}
+
+$bar = null;
+if (!is_countable($bar)) {
+ count($bar);
+}
+?>
+--EXPECTF--
+bool(true)
+bool(true)
+bool(false)
+
+Warning: is_countable() expects exactly 1 parameter, 0 given in %s on line %d
+NULL
+int(2)
+
+Warning: count(): Parameter must be an array or an object that implements Countable in %s on line %d
}
/* }}} */
+/* {{{ proto bool is_countable(mixed var)
+ Returns true if var is countable (array or instance of Countable). */
+PHP_FUNCTION(is_countable)
+{
+ zval *var;
+
+ ZEND_PARSE_PARAMETERS_START(1, 1)
+ Z_PARAM_ZVAL(var)
+ ZEND_PARSE_PARAMETERS_END();
+
+ RETURN_BOOL(zend_is_countable(var));
+}
+/* }}} */
+
/*
* Local variables:
* tab-width: 4