Skip to content

Commit 27e7aea

Browse files
committed
"Countable" interface is moved from SPL to Core
1 parent 44ec732 commit 27e7aea

File tree

10 files changed

+26
-14
lines changed

10 files changed

+26
-14
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PHP NEWS
33
?? ??? ????, PHP 7.2
44

55
- Core:
6+
. "Countable" interface is moved from SPL to Core. (Dmitry)
67
. Added ZEND_IN_ARRAY instruction, implementing optimized in_array() builtin
78
function, through hash lookup in flipped array. (Dmitry)
89
. Removed IS_TYPE_IMMUTABLE (it's the same as COPYABLE & !REFCOUNTED). (Dmitry)

Zend/zend_interfaces.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ZEND_API zend_class_entry *zend_ce_aggregate;
2828
ZEND_API zend_class_entry *zend_ce_iterator;
2929
ZEND_API zend_class_entry *zend_ce_arrayaccess;
3030
ZEND_API zend_class_entry *zend_ce_serializable;
31+
ZEND_API zend_class_entry *zend_ce_countable;
3132

3233
/* {{{ zend_call_method
3334
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
470471
}
471472
/* }}}*/
472473

474+
/* {{{ zend_implement_countable */
475+
static int zend_implement_countable(zend_class_entry *interface, zend_class_entry *class_type)
476+
{
477+
return SUCCESS;
478+
}
479+
/* }}}*/
480+
473481
/* {{{ function tables */
474482
const zend_function_entry zend_funcs_aggregate[] = {
475483
ZEND_ABSTRACT_ME(iterator, getIterator, NULL)
@@ -517,6 +525,14 @@ const zend_function_entry zend_funcs_serializable[] = {
517525
ZEND_FENTRY(unserialize, NULL, arginfo_serializable_serialize, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT|ZEND_ACC_CTOR)
518526
ZEND_FE_END
519527
};
528+
529+
ZEND_BEGIN_ARG_INFO(arginfo_countable_count, 0)
530+
ZEND_END_ARG_INFO()
531+
532+
const zend_function_entry zend_funcs_countable[] = {
533+
ZEND_ABSTRACT_ME(Countable, count, arginfo_countable_count)
534+
ZEND_FE_END
535+
};
520536
/* }}} */
521537

522538
/* {{{ zend_register_interfaces */
@@ -533,6 +549,8 @@ ZEND_API void zend_register_interfaces(void)
533549
REGISTER_MAGIC_INTERFACE(arrayaccess, ArrayAccess);
534550

535551
REGISTER_MAGIC_INTERFACE(serializable, Serializable);
552+
553+
REGISTER_MAGIC_INTERFACE(countable, Countable);
536554
}
537555
/* }}} */
538556

Zend/zend_interfaces.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern ZEND_API zend_class_entry *zend_ce_aggregate;
3131
extern ZEND_API zend_class_entry *zend_ce_iterator;
3232
extern ZEND_API zend_class_entry *zend_ce_arrayaccess;
3333
extern ZEND_API zend_class_entry *zend_ce_serializable;
34+
extern ZEND_API zend_class_entry *zend_ce_countable;
3435

3536
typedef struct _zend_user_iterator {
3637
zend_object_iterator it;

ext/phar/phar_object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5403,12 +5403,12 @@ void phar_object_init(void) /* {{{ */
54035403
INIT_CLASS_ENTRY(ce, "Phar", php_archive_methods);
54045404
phar_ce_archive = zend_register_internal_class_ex(&ce, spl_ce_RecursiveDirectoryIterator);
54055405

5406-
zend_class_implements(phar_ce_archive, 2, spl_ce_Countable, zend_ce_arrayaccess);
5406+
zend_class_implements(phar_ce_archive, 2, zend_ce_countable, zend_ce_arrayaccess);
54075407

54085408
INIT_CLASS_ENTRY(ce, "PharData", php_archive_methods);
54095409
phar_ce_data = zend_register_internal_class_ex(&ce, spl_ce_RecursiveDirectoryIterator);
54105410

5411-
zend_class_implements(phar_ce_data, 2, spl_ce_Countable, zend_ce_arrayaccess);
5411+
zend_class_implements(phar_ce_data, 2, zend_ce_countable, zend_ce_arrayaccess);
54125412

54135413
INIT_CLASS_ENTRY(ce, "PharFileInfo", php_entry_methods);
54145414
phar_ce_entry = zend_register_internal_class_ex(&ce, spl_ce_SplFileInfo);

ext/simplexml/sxe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ PHP_MINIT_FUNCTION(sxe) /* {{{ */
211211
ce_SimpleXMLIterator->create_object = ce_SimpleXMLElement->create_object;
212212

213213
zend_class_implements(ce_SimpleXMLIterator, 1, spl_ce_RecursiveIterator);
214-
zend_class_implements(ce_SimpleXMLIterator, 1, spl_ce_Countable);
214+
zend_class_implements(ce_SimpleXMLIterator, 1, zend_ce_countable);
215215

216216
return SUCCESS;
217217
}

ext/spl/php_spl.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ PHP_FUNCTION(class_uses)
184184
SPL_ADD_CLASS(BadMethodCallException, z_list, sub, allow, ce_flags); \
185185
SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \
186186
SPL_ADD_CLASS(CallbackFilterIterator, z_list, sub, allow, ce_flags); \
187-
SPL_ADD_CLASS(Countable, z_list, sub, allow, ce_flags); \
188187
SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \
189188
SPL_ADD_CLASS(DomainException, z_list, sub, allow, ce_flags); \
190189
SPL_ADD_CLASS(EmptyIterator, z_list, sub, allow, ce_flags); \

ext/spl/spl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ function next();
566566
function valid();
567567
}
568568

569-
/** @ingroup SPL
569+
/** @ingroup ZendEngine
570570
* @brief This Interface allows to hook into the global count() function.
571571
* @since PHP 5.1
572572
*/

ext/spl/spl_iterators.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ PHPAPI zend_class_entry *spl_ce_EmptyIterator;
6060
PHPAPI zend_class_entry *spl_ce_AppendIterator;
6161
PHPAPI zend_class_entry *spl_ce_RegexIterator;
6262
PHPAPI zend_class_entry *spl_ce_RecursiveRegexIterator;
63-
PHPAPI zend_class_entry *spl_ce_Countable;
6463
PHPAPI zend_class_entry *spl_ce_RecursiveTreeIterator;
6564

6665
ZEND_BEGIN_ARG_INFO(arginfo_recursive_it_void, 0)
@@ -3670,11 +3669,6 @@ static const zend_function_entry spl_funcs_OuterIterator[] = {
36703669
PHP_FE_END
36713670
};
36723671

3673-
static const zend_function_entry spl_funcs_Countable[] = {
3674-
SPL_ABSTRACT_ME(Countable, count, arginfo_recursive_it_void)
3675-
PHP_FE_END
3676-
};
3677-
36783672
/* {{{ PHP_MINIT_FUNCTION(spl_iterators)
36793673
*/
36803674
PHP_MINIT_FUNCTION(spl_iterators)
@@ -3729,7 +3723,6 @@ PHP_MINIT_FUNCTION(spl_iterators)
37293723

37303724
REGISTER_SPL_SUB_CLASS_EX(ParentIterator, RecursiveFilterIterator, spl_dual_it_new, spl_funcs_ParentIterator);
37313725

3732-
REGISTER_SPL_INTERFACE(Countable);
37333726
REGISTER_SPL_INTERFACE(SeekableIterator);
37343727
REGISTER_SPL_ITERATOR(SeekableIterator);
37353728

ext/spl/spl_iterators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#define spl_ce_Aggregate zend_ce_aggregate
3333
#define spl_ce_ArrayAccess zend_ce_arrayaccess
3434
#define spl_ce_Serializable zend_ce_serializable
35+
#define spl_ce_Countable zend_ce_countable
3536

3637
extern PHPAPI zend_class_entry *spl_ce_RecursiveIterator;
3738
extern PHPAPI zend_class_entry *spl_ce_RecursiveIteratorIterator;
@@ -51,7 +52,6 @@ extern PHPAPI zend_class_entry *spl_ce_EmptyIterator;
5152
extern PHPAPI zend_class_entry *spl_ce_AppendIterator;
5253
extern PHPAPI zend_class_entry *spl_ce_RegexIterator;
5354
extern PHPAPI zend_class_entry *spl_ce_RecursiveRegexIterator;
54-
extern PHPAPI zend_class_entry *spl_ce_Countable;
5555
extern PHPAPI zend_class_entry *spl_ce_CallbackFilterIterator;
5656
extern PHPAPI zend_class_entry *spl_ce_RecursiveCallbackFilterIterator;
5757

ext/standard/array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ PHP_FUNCTION(count)
813813
}
814814
}
815815
/* if not and the object implements Countable we call its count() method */
816-
if (instanceof_function(Z_OBJCE_P(array), spl_ce_Countable)) {
816+
if (instanceof_function(Z_OBJCE_P(array), zend_ce_countable)) {
817817
zend_call_method_with_0_params(array, NULL, NULL, "count", &retval);
818818
if (Z_TYPE(retval) != IS_UNDEF) {
819819
RETVAL_LONG(zval_get_long(&retval));

0 commit comments

Comments
 (0)