-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Implement Countable for DomNodeList and DOMNamedNodeMap (Request #74837) #2618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,9 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_remove_named_item_ns, 0, 0, 0) | |
ZEND_ARG_INFO(0, namespaceURI) | ||
ZEND_ARG_INFO(0, localName) | ||
ZEND_END_ARG_INFO(); | ||
|
||
ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_namednodemap_count, 0, 0, 0) | ||
ZEND_END_ARG_INFO(); | ||
/* }}} */ | ||
|
||
/* | ||
|
@@ -74,6 +77,7 @@ const zend_function_entry php_dom_namednodemap_class_functions[] = { /* {{{ */ | |
PHP_FALIAS(getNamedItemNS, dom_namednodemap_get_named_item_ns, arginfo_dom_namednodemap_get_named_item_ns) | ||
PHP_FALIAS(setNamedItemNS, dom_namednodemap_set_named_item_ns, arginfo_dom_namednodemap_set_named_item_ns) | ||
PHP_FALIAS(removeNamedItemNS, dom_namednodemap_remove_named_item_ns, arginfo_dom_namednodemap_remove_named_item_ns) | ||
PHP_FALIAS(count, dom_namednodemap_count, arginfo_dom_namednodemap_count) | ||
PHP_FE_END | ||
}; | ||
/* }}} */ | ||
|
@@ -332,6 +336,27 @@ PHP_FUNCTION(dom_namednodemap_remove_named_item_ns) | |
} | ||
/* }}} end dom_namednodemap_remove_named_item_ns */ | ||
|
||
/* {{{ proto int|bool dom_namednodemap_count(); | ||
*/ | ||
PHP_FUNCTION(dom_namednodemap_count) | ||
{ | ||
zval *id; | ||
dom_object *intern; | ||
zval *count; | ||
|
||
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &id, dom_namednodemap_class_entry) == FAILURE) { | ||
return; | ||
} | ||
|
||
intern = Z_DOMOBJ_P(id); | ||
if(dom_namednodemap_length_read(intern, &count)) { | ||
RETURN_FALSE; | ||
} | ||
|
||
RETURN_LONG(count); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something is not right here. You're returning a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What you probably want to do is just pass |
||
} | ||
/* }}} end dom_namednodemap_count */ | ||
|
||
#endif | ||
|
||
/* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -707,6 +707,7 @@ PHP_MINIT_FUNCTION(dom) | |
dom_nodelist_class_entry = zend_register_internal_class_ex(&ce, NULL); | ||
dom_nodelist_class_entry->get_iterator = php_dom_get_iterator; | ||
zend_class_implements(dom_nodelist_class_entry, 1, zend_ce_traversable); | ||
zend_class_implements(dom_nodelist_class_entry, 1, zend_ce_countable); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better to call zend_class_implements once only ... |
||
|
||
zend_hash_init(&dom_nodelist_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1); | ||
dom_register_prop_handler(&dom_nodelist_prop_handlers, "length", sizeof("length")-1, dom_nodelist_length_read, NULL); | ||
|
@@ -717,6 +718,7 @@ PHP_MINIT_FUNCTION(dom) | |
dom_namednodemap_class_entry = zend_register_internal_class_ex(&ce, NULL); | ||
dom_namednodemap_class_entry->get_iterator = php_dom_get_iterator; | ||
zend_class_implements(dom_namednodemap_class_entry, 1, zend_ce_traversable); | ||
zend_class_implements(dom_namednodemap_class_entry, 1, zend_ce_countable); | ||
|
||
zend_hash_init(&dom_namednodemap_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1); | ||
dom_register_prop_handler(&dom_namednodemap_prop_handlers, "length", sizeof("length")-1, dom_namednodemap_length_read, NULL); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--TEST-- | ||
Test count nodes in DOMNamedNodeMap | ||
--CREDITS-- | ||
Andreas Treichel <[email protected]> | ||
--SKIPIF-- | ||
<?php require_once('skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
|
||
$document = new DomDocument(); | ||
$root = $document->createElement('root'); | ||
$document->appendChild($root); | ||
for($i = 0; $i < 5; $i++) { | ||
$root->setAttribute('attribute-' . $i, 'value-' . $i); | ||
} | ||
for($i = 0; $i < 7; $i++) { | ||
$item = $document->createElement('item'); | ||
$root->appendChild($item); | ||
} | ||
var_dump($root->attributes->length); | ||
var_dump($root->attributes->count()); | ||
var_dump(count($root->attributes)); | ||
|
||
?> | ||
--EXPECTF-- | ||
int(5) | ||
int(5) | ||
int(5) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--TEST-- | ||
Test count nodes in DOMNodeList | ||
--CREDITS-- | ||
Andreas Treichel <[email protected]> | ||
--SKIPIF-- | ||
<?php require_once('skipif.inc'); ?> | ||
--FILE-- | ||
<?php | ||
|
||
$document = new DomDocument(); | ||
$root = $document->createElement('root'); | ||
$document->appendChild($root); | ||
for($i = 0; $i < 5; $i++) { | ||
$root->setAttribute('attribute-' . $i, 'value-' . $i); | ||
} | ||
for($i = 0; $i < 7; $i++) { | ||
$item = $document->createElement('item'); | ||
$root->appendChild($item); | ||
} | ||
var_dump($root->childNodes->length); | ||
var_dump($root->childNodes->count()); | ||
var_dump(count($root->childNodes)); | ||
|
||
?> | ||
--EXPECTF-- | ||
int(7) | ||
int(7) | ||
int(7) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should compare against SUCCESS or FAILURE.