From 9eaee687d32d807484422f4542985dd642e3815c Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 29 Dec 2024 14:37:25 +0100 Subject: [PATCH] Revert 746b1cf4 "Access long value directly for call to count() in simplexml" The count() function has a tentative return type. Add a comment for the future. --- ext/simplexml/simplexml.c | 5 +++-- .../tests/count_return_type_will_change.phpt | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 ext/simplexml/tests/count_return_type_will_change.phpt diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 7fc5ad35abc92..a00b152f9c089 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1928,8 +1928,9 @@ static zend_result sxe_count_elements(zend_object *object, zend_long *count) /* zval rv; zend_call_method_with_0_params(object, intern->zo.ce, &intern->fptr_count, "count", &rv); if (!Z_ISUNDEF(rv)) { - ZEND_ASSERT(Z_TYPE(rv) == IS_LONG); - *count = Z_LVAL(rv); + /* TODO: change this to Z_LVAL_P() once the tentative type on count() is gone. */ + *count = zval_get_long(&rv); + zval_ptr_dtor(&rv); return SUCCESS; } return FAILURE; diff --git a/ext/simplexml/tests/count_return_type_will_change.phpt b/ext/simplexml/tests/count_return_type_will_change.phpt new file mode 100644 index 0000000000000..20cbca01ba8b8 --- /dev/null +++ b/ext/simplexml/tests/count_return_type_will_change.phpt @@ -0,0 +1,20 @@ +--TEST-- +SimpleXMLElement::count() interaction with ReturnTypeWillChange +--EXTENSIONS-- +simplexml +--FILE-- +", CustomClass::class); +var_dump(count($sxe)); + +?> +--EXPECT-- +int(3)