return 0;
}
+/* TODO Document this function on php.net */
PHP_FUNCTION(mb_str_split)
{
zend_string *str, *encoding = NULL;
ZEND_PARSE_PARAMETERS_END();
if (split_length <= 0) {
- php_error_docref(NULL, E_WARNING, "The length of each segment must be greater than zero");
- RETURN_FALSE;
+ zend_argument_value_error(2, "must be greater than 0");
+ RETURN_THROWS();
}
/* fill mbfl_string structure */
mbfl_memory_device_output,
NULL,
&device);
- /* if something wrong with the decoded */
- if (decoder == NULL) {
- RETURN_FALSE;
- }
+ /* assert that nothing is wrong with the decoder */
+ ZEND_ASSERT(decoder != NULL);
/* wchar filter */
mbfl_string_init(&result_string); /* mbfl_string to store chunk in the callback */
mbfl_split_output,
NULL,
¶ms);
- /* if something wrong with the filter */
- if (filter == NULL){
- mbfl_convert_filter_delete(decoder); /* this will free allocated memory for the decoded */
- RETURN_FALSE;
- }
+ /* assert that nothing is wrong with the filter */
+ ZEND_ASSERT(filter != NULL);
while (p < last - 1) { /* cycle each byte except last with callback function */
(*filter->filter_function)(*p++, filter);
function mb_output_handler(string $contents, int $status): string {}
-function mb_str_split(string $str, int $split_length = 1, string $encoding = UNKNOWN): array|false {}
+function mb_str_split(string $str, int $split_length = 1, string $encoding = UNKNOWN): array {}
function mb_strlen(string $str, string $encoding = UNKNOWN): int|false {}
ZEND_ARG_TYPE_INFO(0, status, IS_LONG, 0)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_str_split, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_str_split, 0, 1, IS_ARRAY, 0)
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, split_length, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
--- /dev/null
+--TEST--
+mb_str_split() error conditions
+--SKIPIF--
+<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
+--FILE--
+<?php
+
+$string = "日本"; /* 2 chars */
+
+// Invalid split length
+try {
+ mb_str_split($string, 0);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ mb_str_split($string, -5);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+//Invalid Encoding
+try {
+ mb_str_split($string, 1, "BAD_ENCODING");
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+?>
+--EXPECT--
+mb_str_split(): Argument #2 ($split_length) must be greater than 0
+mb_str_split(): Argument #2 ($split_length) must be greater than 0
+mb_str_split(): Argument #3 ($encoding) must be a valid encoding, "BAD_ENCODING" given