From 27e7aea4124ffdecb6d40a2f5723e413a7b40562 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Thu, 25 May 2017 12:47:43 +0300 Subject: [PATCH] "Countable" interface is moved from SPL to Core --- NEWS | 1 + Zend/zend_interfaces.c | 18 ++++++++++++++++++ Zend/zend_interfaces.h | 1 + ext/phar/phar_object.c | 4 ++-- ext/simplexml/sxe.c | 2 +- ext/spl/php_spl.c | 1 - ext/spl/spl.php | 2 +- ext/spl/spl_iterators.c | 7 ------- ext/spl/spl_iterators.h | 2 +- ext/standard/array.c | 2 +- 10 files changed, 26 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index 483de90cab..e0a9e92d8e 100644 --- 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) diff --git a/Zend/zend_interfaces.c b/Zend/zend_interfaces.c index 6bf4b15c67..e078c7f6b2 100644 --- a/Zend/zend_interfaces.c +++ b/Zend/zend_interfaces.c @@ -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); } /* }}} */ diff --git a/Zend/zend_interfaces.h b/Zend/zend_interfaces.h index 9166ccf48a..fbb8470500 100644 --- a/Zend/zend_interfaces.h +++ b/Zend/zend_interfaces.h @@ -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; diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index f94aa19de7..694b4b9377 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -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); diff --git a/ext/simplexml/sxe.c b/ext/simplexml/sxe.c index e1fbc63872..cb15f007d9 100644 --- a/ext/simplexml/sxe.c +++ b/ext/simplexml/sxe.c @@ -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; } diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 092fc54872..34b54e81e1 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -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); \ diff --git a/ext/spl/spl.php b/ext/spl/spl.php index ff9d1b6bbe..8a68613417 100755 --- a/ext/spl/spl.php +++ b/ext/spl/spl.php @@ -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 */ diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 6690c4a8f7..0048f2107d 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -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); diff --git a/ext/spl/spl_iterators.h b/ext/spl/spl_iterators.h index f9b84b7390..dd86c0ea9a 100644 --- a/ext/spl/spl_iterators.h +++ b/ext/spl/spl_iterators.h @@ -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; diff --git a/ext/standard/array.c b/ext/standard/array.c index 2744ee3306..8968f4f821 100644 --- a/ext/standard/array.c +++ b/ext/standard/array.c @@ -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)); -- 2.40.0