]> granicus.if.org Git - php/commitdiff
"Countable" interface is moved from SPL to Core
authorDmitry Stogov <dmitry@zend.com>
Thu, 25 May 2017 09:47:43 +0000 (12:47 +0300)
committerDmitry Stogov <dmitry@zend.com>
Thu, 25 May 2017 09:47:43 +0000 (12:47 +0300)
NEWS
Zend/zend_interfaces.c
Zend/zend_interfaces.h
ext/phar/phar_object.c
ext/simplexml/sxe.c
ext/spl/php_spl.c
ext/spl/spl.php
ext/spl/spl_iterators.c
ext/spl/spl_iterators.h
ext/standard/array.c

diff --git a/NEWS b/NEWS
index 483de90cab9c919ef5b86adda1686643cd525c19..e0a9e92d8e78b08e55d2fe348dd5bd3d1ec7999e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ PHP                                                                        NEWS
 ?? ??? ????, PHP 7.2
 
 - Core:
+  . "Countable" interface is moved from SPL to Core. (Dmitry)
   . Added ZEND_IN_ARRAY instruction, implementing optimized in_array() builtin
     function, through hash lookup in flipped array. (Dmitry)
   . Removed IS_TYPE_IMMUTABLE (it's the same as COPYABLE & !REFCOUNTED). (Dmitry)
index 6bf4b15c670e538a3823355b5fc1f5f0a6ea18fd..e078c7f6b2c50c6899c163b63c23692101f0b717 100644 (file)
@@ -28,6 +28,7 @@ ZEND_API zend_class_entry *zend_ce_aggregate;
 ZEND_API zend_class_entry *zend_ce_iterator;
 ZEND_API zend_class_entry *zend_ce_arrayaccess;
 ZEND_API zend_class_entry *zend_ce_serializable;
+ZEND_API zend_class_entry *zend_ce_countable;
 
 /* {{{ zend_call_method
  Only returns the returned zval if retval_ptr != NULL */
@@ -470,6 +471,13 @@ static int zend_implement_serializable(zend_class_entry *interface, zend_class_e
 }
 /* }}}*/
 
+/* {{{ zend_implement_countable */
+static int zend_implement_countable(zend_class_entry *interface, zend_class_entry *class_type)
+{
+       return SUCCESS;
+}
+/* }}}*/
+
 /* {{{ function tables */
 const zend_function_entry zend_funcs_aggregate[] = {
        ZEND_ABSTRACT_ME(iterator, getIterator, NULL)
@@ -517,6 +525,14 @@ const zend_function_entry zend_funcs_serializable[] = {
        ZEND_FENTRY(unserialize, NULL, arginfo_serializable_serialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT|ZEND_ACC_CTOR)
        ZEND_FE_END
 };
+
+ZEND_BEGIN_ARG_INFO(arginfo_countable_count, 0)
+ZEND_END_ARG_INFO()
+
+const zend_function_entry zend_funcs_countable[] = {
+       ZEND_ABSTRACT_ME(Countable, count, arginfo_countable_count)
+       ZEND_FE_END
+};
 /* }}} */
 
 /* {{{ zend_register_interfaces */
@@ -533,6 +549,8 @@ ZEND_API void zend_register_interfaces(void)
        REGISTER_MAGIC_INTERFACE(arrayaccess, ArrayAccess);
 
        REGISTER_MAGIC_INTERFACE(serializable, Serializable);
+
+       REGISTER_MAGIC_INTERFACE(countable, Countable);
 }
 /* }}} */
 
index 9166ccf48a170fd7a189842fe5e041e78487a091..fbb84705001e328382476869cb02244bbee34d3f 100644 (file)
@@ -31,6 +31,7 @@ extern ZEND_API zend_class_entry *zend_ce_aggregate;
 extern ZEND_API zend_class_entry *zend_ce_iterator;
 extern ZEND_API zend_class_entry *zend_ce_arrayaccess;
 extern ZEND_API zend_class_entry *zend_ce_serializable;
+extern ZEND_API zend_class_entry *zend_ce_countable;
 
 typedef struct _zend_user_iterator {
        zend_object_iterator     it;
index f94aa19de7835420147c3f42641d83321690002e..694b4b93778c444802173b907c93765b03bd3f76 100644 (file)
@@ -5403,12 +5403,12 @@ void phar_object_init(void) /* {{{ */
        INIT_CLASS_ENTRY(ce, "Phar", php_archive_methods);
        phar_ce_archive = zend_register_internal_class_ex(&ce, spl_ce_RecursiveDirectoryIterator);
 
-       zend_class_implements(phar_ce_archive, 2, spl_ce_Countable, zend_ce_arrayaccess);
+       zend_class_implements(phar_ce_archive, 2, zend_ce_countable, zend_ce_arrayaccess);
 
        INIT_CLASS_ENTRY(ce, "PharData", php_archive_methods);
        phar_ce_data = zend_register_internal_class_ex(&ce, spl_ce_RecursiveDirectoryIterator);
 
-       zend_class_implements(phar_ce_data, 2, spl_ce_Countable, zend_ce_arrayaccess);
+       zend_class_implements(phar_ce_data, 2, zend_ce_countable, zend_ce_arrayaccess);
 
        INIT_CLASS_ENTRY(ce, "PharFileInfo", php_entry_methods);
        phar_ce_entry = zend_register_internal_class_ex(&ce, spl_ce_SplFileInfo);
index e1fbc6387273a3c6825139b37d040e695fe37204..cb15f007d94865c1a4eb36df66e2436b2e22343e 100644 (file)
@@ -211,7 +211,7 @@ PHP_MINIT_FUNCTION(sxe) /* {{{ */
        ce_SimpleXMLIterator->create_object = ce_SimpleXMLElement->create_object;
 
        zend_class_implements(ce_SimpleXMLIterator, 1, spl_ce_RecursiveIterator);
-       zend_class_implements(ce_SimpleXMLIterator, 1, spl_ce_Countable);
+       zend_class_implements(ce_SimpleXMLIterator, 1, zend_ce_countable);
 
        return SUCCESS;
 }
index 092fc54872aca3c933d56343ea231adc707d95b3..34b54e81e1ddbf06bdb002945f4b4ba83f6b2cd1 100644 (file)
@@ -184,7 +184,6 @@ PHP_FUNCTION(class_uses)
        SPL_ADD_CLASS(BadMethodCallException, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(CallbackFilterIterator, z_list, sub, allow, ce_flags); \
-       SPL_ADD_CLASS(Countable, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(DomainException, z_list, sub, allow, ce_flags); \
        SPL_ADD_CLASS(EmptyIterator, z_list, sub, allow, ce_flags); \
index ff9d1b6bbe1109880b528aca4af402e0c7faaa25..8a68613417f4144d749340b2406449bdcfbfa2ef 100755 (executable)
@@ -566,7 +566,7 @@ interface Iterator extends Traversable
        function valid();
 }
 
-/** @ingroup SPL
+/** @ingroup ZendEngine
  * @brief This Interface allows to hook into the global count() function.
  * @since PHP 5.1
  */
index 6690c4a8f765d9f430a236ebae31a6fb8ff93e43..0048f2107d24e88e8992f1d47f32cd6e105274bc 100644 (file)
@@ -60,7 +60,6 @@ PHPAPI zend_class_entry *spl_ce_EmptyIterator;
 PHPAPI zend_class_entry *spl_ce_AppendIterator;
 PHPAPI zend_class_entry *spl_ce_RegexIterator;
 PHPAPI zend_class_entry *spl_ce_RecursiveRegexIterator;
-PHPAPI zend_class_entry *spl_ce_Countable;
 PHPAPI zend_class_entry *spl_ce_RecursiveTreeIterator;
 
 ZEND_BEGIN_ARG_INFO(arginfo_recursive_it_void, 0)
@@ -3670,11 +3669,6 @@ static const zend_function_entry spl_funcs_OuterIterator[] = {
        PHP_FE_END
 };
 
-static const zend_function_entry spl_funcs_Countable[] = {
-       SPL_ABSTRACT_ME(Countable, count,   arginfo_recursive_it_void)
-       PHP_FE_END
-};
-
 /* {{{ PHP_MINIT_FUNCTION(spl_iterators)
  */
 PHP_MINIT_FUNCTION(spl_iterators)
@@ -3729,7 +3723,6 @@ PHP_MINIT_FUNCTION(spl_iterators)
 
        REGISTER_SPL_SUB_CLASS_EX(ParentIterator, RecursiveFilterIterator, spl_dual_it_new, spl_funcs_ParentIterator);
 
-       REGISTER_SPL_INTERFACE(Countable);
        REGISTER_SPL_INTERFACE(SeekableIterator);
        REGISTER_SPL_ITERATOR(SeekableIterator);
 
index f9b84b7390dbbf455a3851995419de6ad8f349c1..dd86c0ea9a3e197420f9eaa25d0c35dab8487a52 100644 (file)
@@ -32,6 +32,7 @@
 #define spl_ce_Aggregate     zend_ce_aggregate
 #define spl_ce_ArrayAccess   zend_ce_arrayaccess
 #define spl_ce_Serializable  zend_ce_serializable
+#define spl_ce_Countable     zend_ce_countable
 
 extern PHPAPI zend_class_entry *spl_ce_RecursiveIterator;
 extern PHPAPI zend_class_entry *spl_ce_RecursiveIteratorIterator;
@@ -51,7 +52,6 @@ extern PHPAPI zend_class_entry *spl_ce_EmptyIterator;
 extern PHPAPI zend_class_entry *spl_ce_AppendIterator;
 extern PHPAPI zend_class_entry *spl_ce_RegexIterator;
 extern PHPAPI zend_class_entry *spl_ce_RecursiveRegexIterator;
-extern PHPAPI zend_class_entry *spl_ce_Countable;
 extern PHPAPI zend_class_entry *spl_ce_CallbackFilterIterator;
 extern PHPAPI zend_class_entry *spl_ce_RecursiveCallbackFilterIterator;
 
index 2744ee33069ab0ba0f5797d3472155548aabf4be..8968f4f821e6b5ae7d0b8a68756e3c4ad41da8f4 100644 (file)
@@ -813,7 +813,7 @@ PHP_FUNCTION(count)
                                }
                        }
                        /* if not and the object implements Countable we call its count() method */
-                       if (instanceof_function(Z_OBJCE_P(array), spl_ce_Countable)) {
+                       if (instanceof_function(Z_OBJCE_P(array), zend_ce_countable)) {
                                zend_call_method_with_0_params(array, NULL, NULL, "count", &retval);
                                if (Z_TYPE(retval) != IS_UNDEF) {
                                        RETVAL_LONG(zval_get_long(&retval));