Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/dom/dom_fe.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ PHP_METHOD(domnode, getLineNo);

/* domnodelist methods */
PHP_FUNCTION(dom_nodelist_item);
PHP_FUNCTION(dom_nodelist_count);

/* domnamednodemap methods */
PHP_FUNCTION(dom_namednodemap_get_named_item);
Expand All @@ -181,6 +182,7 @@ PHP_FUNCTION(dom_namednodemap_item);
PHP_FUNCTION(dom_namednodemap_get_named_item_ns);
PHP_FUNCTION(dom_namednodemap_set_named_item_ns);
PHP_FUNCTION(dom_namednodemap_remove_named_item_ns);
PHP_FUNCTION(dom_namednodemap_count);

/* domcharacterdata methods */
PHP_FUNCTION(dom_characterdata_substring_data);
Expand Down
25 changes: 25 additions & 0 deletions ext/dom/namednodemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
/* }}} */

/*
Expand All @@ -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
};
/* }}} */
Expand Down Expand Up @@ -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)) {
Copy link
Member

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.

RETURN_FALSE;
}

RETURN_LONG(count);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is not right here. You're returning a zval * as a zend_long here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you probably want to do is just pass return_value as the second argument to dom_namednodemap_length_read.

}
/* }}} end dom_namednodemap_count */

#endif

/*
Expand Down
29 changes: 29 additions & 0 deletions ext/dom/nodelist.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_nodelist_item, 0, 0, 1)
ZEND_END_ARG_INFO();
/* }}} */

/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_nodelist_count, 0, 0, 0)
ZEND_END_ARG_INFO();
/* }}} */

/*
* class DOMNodeList
*
Expand All @@ -43,9 +48,11 @@ ZEND_END_ARG_INFO();

const zend_function_entry php_dom_nodelist_class_functions[] = {
PHP_FALIAS(item, dom_nodelist_item, arginfo_dom_nodelist_item)
PHP_FALIAS(count, dom_nodelist_count, arginfo_dom_nodelist_count)
PHP_FE_END
};


/* {{{ length int
readonly=yes
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-203510337
Expand Down Expand Up @@ -96,6 +103,27 @@ int dom_nodelist_length_read(dom_object *obj, zval *retval)
return SUCCESS;
}


/* {{{ proto int|bool dom_nodelist_count();
*/
PHP_FUNCTION(dom_nodelist_count)
{
zval *id;
dom_object *intern;
zval *count;

if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &id, dom_nodelist_class_entry) == FAILURE) {
return;
}

intern = Z_DOMOBJ_P(id);
if(dom_nodelist_length_read(intern, &count)) {
RETURN_FALSE;
}
RETURN_LONG(count);
}
/* }}} end dom_nodelist_count */

/* }}} */

/* {{{ proto DOMNode dom_nodelist_item(int index);
Expand Down Expand Up @@ -170,6 +198,7 @@ PHP_FUNCTION(dom_nodelist_item)
}
/* }}} end dom_nodelist_item */


#endif

/*
Expand Down
2 changes: 2 additions & 0 deletions ext/dom/php_dom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The 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);
Expand All @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions ext/dom/tests/DOMNamedNodeMap_count.phpt
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)
28 changes: 28 additions & 0 deletions ext/dom/tests/DomNodeList_count.phpt
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)