Skip to content

Commit bfc1097

Browse files
LeSuissecmb69
authored andcommitted
SimpleXMLElement and ResourceBundle implement Countable
Both classes already have a count() method and are considered countable by \is_countable().
1 parent 7f26171 commit bfc1097

File tree

6 files changed

+40
-2
lines changed

6 files changed

+40
-2
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ PHP NEWS
7474

7575
- Intl:
7676
. Raised requirements to ICU ≥ 50.1. (cmb)
77+
. Changed ResourceBundle to implement Countable. (LeSuisse)
7778
. Changed default of $variant parameter of idn_to_ascii() and idn_to_utf8().
7879
(cmb)
7980

@@ -121,6 +122,10 @@ PHP NEWS
121122
(krakjoe)
122123
. Fixed bug #77805 (phpdbg build fails when readline is shared). (krakjoe)
123124

125+
- SimpleXML:
126+
. Implemented FR #65215 (SimpleXMLElement could register as implementing
127+
Countable). (LeSuisse)
128+
124129
- Sockets:
125130
. Fixed bug #67619 (Validate length on socket_write). (thiagooak)
126131

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ PHP 7.4 UPGRADE NOTES
402402

403403
- Intl:
404404
. The Intl extension now requires at least ICU 50.1.
405+
. ResourceBundle now implements Countable.
405406

406407
- Libxml:
407408
. All libxml based extensions now require libxml 2.7.6 or newer.
@@ -422,6 +423,9 @@ PHP 7.4 UPGRADE NOTES
422423
results of Reflection...::getModifiers(), using hard-coded numeric values.
423424
Use corresponding constants instead (e.g. ReflectionMethod::IS_PUBLIC).
424425

426+
- SimpleXML:
427+
. SimpleXMLElement now implements Countable.
428+
425429
- SQLite3:
426430
. The bundled libsqlite has been removed. To build the SQLite3 extension
427431
a system libsqlite3 ≥ 3.7.4 is now required. To build the PDO_SQLite

ext/intl/resourcebundle/resourcebundle_class.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,6 @@ void resourcebundle_register_class( void )
455455
ResourceBundle_object_handlers.read_dimension = resourcebundle_array_get;
456456
ResourceBundle_object_handlers.count_elements = resourcebundle_array_count;
457457

458-
zend_class_implements(ResourceBundle_ce_ptr, 1, zend_ce_traversable);
458+
zend_class_implements(ResourceBundle_ce_ptr, 2, zend_ce_traversable, zend_ce_countable);
459459
}
460460
/* }}} */
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Test ResourceBundle implements Countable
3+
--SKIPIF--
4+
<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
5+
--FILE--
6+
<?php
7+
include "resourcebundle.inc";
8+
9+
$r = new ResourceBundle( 'es', BUNDLE );
10+
11+
var_dump($r instanceof Countable);
12+
?>
13+
--EXPECT--
14+
bool(true)

ext/simplexml/simplexml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2686,7 +2686,7 @@ PHP_MINIT_FUNCTION(simplexml)
26862686
sxe.create_object = sxe_object_new;
26872687
sxe_class_entry = zend_register_internal_class(&sxe);
26882688
sxe_class_entry->get_iterator = php_sxe_get_iterator;
2689-
zend_class_implements(sxe_class_entry, 1, zend_ce_traversable);
2689+
zend_class_implements(sxe_class_entry, 2, zend_ce_traversable, zend_ce_countable);
26902690

26912691
memcpy(&sxe_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
26922692
sxe_object_handlers.offset = XtOffsetOf(php_sxe_object, zo);

ext/simplexml/tests/037.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
SimpleXML: implement Countable
3+
--SKIPIF--
4+
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
$str = '<xml></xml>';
9+
$sxe = new SimpleXmlElement($str);
10+
var_dump($sxe instanceof Countable);
11+
?>
12+
==Done==
13+
--EXPECT--
14+
bool(true)
15+
==Done==

0 commit comments

Comments
 (0)