Skip to content

Intl: Add a new IntlListFormatter class #18519

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

Closed
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
Prev Previous commit
Next Next commit
disable cloning and use different functions
  • Loading branch information
BogdanUngureanu committed May 16, 2025
commit 5d2ca4c5d5073fd6d59ba6aaa7df94a810fe6515
8 changes: 4 additions & 4 deletions ext/intl/listformatter/listformatter_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,18 @@ PHP_METHOD(IntlListFormatter, __construct)
PHP_METHOD(IntlListFormatter, format)
{
ListFormatter_object *obj = Z_INTL_LISTFORMATTER_P(ZEND_THIS);
zval *strings;
HashTable *ht;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_ARRAY(strings)
Z_PARAM_ARRAY_HT(ht)
ZEND_PARSE_PARAMETERS_END();

if (!LISTFORMATTER_OBJECT(obj)) {
zend_throw_exception(NULL, "ListFormatter not properly constructed", 0);
RETURN_FALSE;
}

HashTable *ht = Z_ARRVAL_P(strings);
uint32_t count = zend_array_count(ht);
uint32_t count = zend_hash_num_elements(ht);
if (count == 0) {
RETURN_EMPTY_STRING();
}
Expand Down Expand Up @@ -238,4 +237,5 @@ void listformatter_register_class(void)
memcpy(&listformatter_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
listformatter_handlers.offset = XtOffsetOf(ListFormatter_object, zo);
listformatter_handlers.free_obj = listformatter_free_obj;
listformatter_handlers.clone_obj = NULL;
}
2 changes: 1 addition & 1 deletion ext/intl/listformatter/listformatter_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ static inline ListFormatter_object *php_intl_listformatter_fetch_object(zend_obj
void listformatter_register_class( void );
extern zend_class_entry *ListFormatter_ce_ptr;

#endif // LISTFORMATTER_CLASS_H
#endif // LISTFORMATTER_CLASS_H
2 changes: 1 addition & 1 deletion ext/intl/tests/listformatter/listformatter_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ test, test2, and test
FR
1, 2 et 3
1, 2 et 3
1.2, 2.3 et 3.4
1.2, 2.3 et 3.4
22 changes: 22 additions & 0 deletions ext/intl/tests/listformatter/listformatter_clone.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Test IntlListFormatter cannot be cloned
--SKIPIF--
<?php
if (!extension_loaded('intl')) {
die('skip intl extension not available');
}
?>
--FILE--
<?php

$formatter = new IntlListFormatter('en_US', IntlListFormatter::TYPE_AND, IntlListFormatter::WIDTH_WIDE);

try {
$clonedFormatter = clone $formatter;
} catch(Error $error) {
echo $error->getMessage();
}

?>
--EXPECT--
Trying to clone an uncloneable object of class IntlListFormatter
2 changes: 1 addition & 1 deletion ext/intl/tests/listformatter/listformatter_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ try {
IntlListFormatter::__construct(): Argument #1 ($locale) "f" is invalid
IntlListFormatter::__construct(): Argument #1 ($locale) Locale string too long, should be no longer than 156 characters
Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Object of class stdClass could not be converted to string
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ FR
1, 2 ou 3
1, 2 et 3
1, 2 et 3
1 2 3
1 2 3
Loading