} else {
zend_string *ini_name = zend_string_init("mbstring.language", sizeof("mbstring.language") - 1, 0);
if (FAILURE == zend_alter_ini_entry(ini_name, name, PHP_INI_USER, PHP_INI_STAGE_RUNTIME)) {
- php_error_docref(NULL, E_WARNING, "Unknown language \"%s\"", ZSTR_VAL(name));
- RETVAL_FALSE;
- } else {
- RETVAL_TRUE;
+ zend_argument_value_error(1, "must be a valid language, \"%s\" given", ZSTR_VAL(name));
+ zend_string_release_ex(ini_name, 0);
+ RETURN_THROWS();
}
+ // TODO Make return void
+ RETVAL_TRUE;
zend_string_release_ex(ini_name, 0);
}
}
if (size == 0) {
efree(list);
- php_error_docref(NULL, E_WARNING, "Must specify at least one encoding");
- RETURN_FALSE;
+ zend_argument_value_error(1, "must specify at least one encoding");
+ RETURN_THROWS();
}
if (MBSTRG(current_detect_order_list)) {
}
if (from < 0 || (size_t)from > str_len) {
- php_error_docref(NULL, E_WARNING, "Start position is out of range");
- RETURN_FALSE;
+ zend_argument_value_error(2, "is out of range");
+ RETURN_THROWS();
}
if (width < 0) {
}
if (width < 0) {
- php_error_docref(NULL, E_WARNING, "Width is out of range");
- RETURN_FALSE;
+ zend_argument_value_error(3, "is out of range");
+ RETURN_THROWS();
}
if (trimmarker) {
if (!num_from_encodings) {
efree(from_encodings);
- php_error_docref(NULL, E_WARNING, "Must specify at least one encoding");
- RETURN_FALSE;
+ zend_argument_value_error(3, "must specify at least one encoding");
+ RETURN_THROWS();
}
if (input_str) {
if (size == 0) {
efree(elist);
- php_error_docref(NULL, E_WARNING, "Must specify at least one encoding");
- RETURN_FALSE;
+ zend_argument_value_error(2, "must specify at least one encoding");
+ RETURN_THROWS();
}
if (ZEND_NUM_ARGS() < 3) {
if (elistsz == 0) {
efree(elist);
- php_error_docref(NULL, E_WARNING, "Must specify at least one encoding");
- RETURN_FALSE;
+ zend_argument_value_error(2, "must specify at least one encoding");
+ RETURN_THROWS();
}
if (elistsz == 1) {
--- /dev/null
+--TEST--
+Test mb_convert_encoding() function : empty encoding list
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+function_exists('mb_convert_encoding') or die("skip mb_convert_encoding() is not available in this build");
+?>
+--FILE--
+<?php
+
+$string = 'Hello';
+
+try {
+ var_dump( mb_convert_encoding($string, 'UTF-8', ''));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump( mb_convert_encoding($string, 'UTF-8', []));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+?>
+--EXPECT--
+mb_convert_encoding(): Argument #3 ($from) must specify at least one encoding
+mb_convert_encoding(): Argument #3 ($from) must specify at least one encoding
--- /dev/null
+--TEST--
+Test mb_convert_variables() function : empty encoding list
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+?>
+--FILE--
+<?php
+
+$string = 'Hello';
+
+try {
+ var_dump( mb_convert_variables('UTF-8', '', $string));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump( mb_convert_variables('UTF-8', [], $string));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+?>
+--EXPECT--
+mb_convert_variables(): Argument #2 ($from) must specify at least one encoding
+mb_convert_variables(): Argument #2 ($from) must specify at least one encoding
--- /dev/null
+--TEST--
+Test mb_detect_encoding() function : empty encoding list
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+?>
+--FILE--
+<?php
+
+$string = 'Hello';
+
+try {
+ var_dump( mb_detect_encoding($string, ''));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump( mb_detect_encoding($string, []));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+?>
+--EXPECT--
+mb_detect_encoding(): Argument #2 ($encoding_list) must specify at least one encoding
+mb_detect_encoding(): Argument #2 ($encoding_list) must specify at least one encoding
--- /dev/null
+--TEST--
+Test mb_detect_order() function : empty encoding list
+--SKIPIF--
+<?php
+extension_loaded('mbstring') or die('skip');
+?>
+--FILE--
+<?php
+
+try {
+ var_dump( mb_detect_order(''));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump( mb_detect_order([]));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+?>
+--EXPECT--
+mb_detect_order(): Argument #1 ($encoding) must specify at least one encoding
+mb_detect_order(): Argument #1 ($encoding) must specify at least one encoding
var_dump(mb_language());
echo "Try changing to a non-existent language:\n";
-var_dump(mb_language('Pig Latin'));
+try {
+ var_dump(mb_language('Pig Latin'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump(mb_language());
?>
---EXPECTF--
+--EXPECT--
Checking default language:
string(7) "neutral"
Checking default language after ini_set:
Confirm language was changed:
string(7) "English"
Try changing to a non-existent language:
-
-Warning: mb_language(): Unknown language "Pig Latin" in %s on line %d
-bool(false)
+mb_language(): Argument #1 ($language) must be a valid language, "Pig Latin" given
string(7) "neutral"
print "6: ". mb_strimwidth($euc_jp, 38, -25,'...','EUC-JP') . "\n";
print "7: ". mb_strimwidth($euc_jp, -30, -25,'...','EUC-JP') . "\n";
-$str = mb_strimwidth($euc_jp, 0, -100,'...','EUC-JP');
-($str === FALSE) ? print "10 OK\n" : print "NG: $str\n";
-
-$str = mb_strimwidth($euc_jp, 100, 10,'...','EUC-JP');
-($str === FALSE) ? print "11 OK\n" : print "NG: $str\n";
-
-$str = mb_strimwidth($euc_jp, -100, 10,'...','EUC-JP');
-($str === FALSE) ? print "12 OK\n" : print "NG: $str\n";
-
-$str = mb_strimwidth($euc_jp, -10, -12,'...','EUC-JP');
-($str === FALSE) ? print "13 OK\n" : print "NG: $str\n";
+try {
+ var_dump(mb_strimwidth($euc_jp, 0, -100,'...','EUC-JP'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(mb_strimwidth($euc_jp, 100, 10,'...','EUC-JP'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(mb_strimwidth($euc_jp, -100, 10,'...','EUC-JP'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(mb_strimwidth($euc_jp, -10, -12,'...','EUC-JP'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
---EXPECTF--
+--EXPECT--
String width: 68
1: 0123¤³¤Îʸ»ú...
2: 0123¤³¤Îʸ»úÎó¤ÏÆüËܸì¤Ç¤¹¡£EUC-JP¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£ÆüËܸì¤ÏÌÌÅݽ¤¤¡£
5: ¡£
6: ¡£
7: ¡£
-
-Warning: mb_strimwidth(): Width is out of range in %s on line %d
-10 OK
-
-Warning: mb_strimwidth(): Start position is out of range in %s on line %d
-11 OK
-
-Warning: mb_strimwidth(): Start position is out of range in %s on line %d
-12 OK
-
-Warning: mb_strimwidth(): Width is out of range in %s on line %d
-13 OK
+mb_strimwidth(): Argument #3 ($width) is out of range
+mb_strimwidth(): Argument #2 ($start) is out of range
+mb_strimwidth(): Argument #2 ($start) is out of range
+mb_strimwidth(): Argument #3 ($width) is out of range