RETURN_THROWS();
}
+ if (needle.len == 0) {
+ zend_argument_value_error(2, "must not be empty");
+ RETURN_THROWS();
+ }
+
haystack.no_language = needle.no_language = MBSTRG(language);
haystack.encoding = needle.encoding = php_mb_get_encoding(enc_name, 3);
if (!haystack.encoding) {
RETURN_THROWS();
}
- if (needle.len == 0) {
- php_error_docref(NULL, E_WARNING, "Empty substring");
- RETURN_FALSE;
- }
-
n = mbfl_substr_count(&haystack, &needle);
- if (!mbfl_is_error(n)) {
- RETVAL_LONG(n);
- } else {
- RETVAL_FALSE;
- }
+ /* An error can only occur if needle is empty,
+ * an encoding error happens (which should not happen at this stage and is a bug)
+ * or the haystack is more than sizeof(size_t) bytes
+ * If one of these things occur this is a bug and should be flagged as such */
+ ZEND_ASSERT(!mbfl_is_error(n));
+ RETVAL_LONG(n);
}
/* }}} */
function mb_strrichr(string $haystack, string $needle, bool $part = false, string $encoding = UNKNOWN): string|false {}
-function mb_substr_count(string $haystack, string $needle, string $encoding = UNKNOWN): int|false {}
+function mb_substr_count(string $haystack, string $needle, string $encoding = UNKNOWN): int {}
function mb_substr(string $str, int $start, ?int $length = null, string $encoding = UNKNOWN): string|false {}
#define arginfo_mb_strrichr arginfo_mb_strstr
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_substr_count, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_substr_count, 0, 2, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0)
--FILE--
<?php
mb_internal_encoding("EUC-JP");
- var_dump(@mb_substr_count("", ""));
- var_dump(@mb_substr_count("¤¢", ""));
- var_dump(@mb_substr_count("", "¤¢"));
- var_dump(@mb_substr_count("", "¤¢"));
- var_dump(@mb_substr_count("", chr(0)));
+ try {
+ var_dump(mb_substr_count("", ""));
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
+ try {
+ var_dump(mb_substr_count("��", ""));
+ } catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+ }
+
+ var_dump(mb_substr_count("", "¤¢"));
+ var_dump(mb_substr_count("", "¤¢"));
+ var_dump(mb_substr_count("", chr(0)));
$a = str_repeat("abcacba", 100);
var_dump(@mb_substr_count($a, "bca"));
var_dump(@mb_substr_count($a, "bca"));
?>
--EXPECT--
-bool(false)
-bool(false)
+mb_substr_count(): Argument #2 ($needle) must not be empty
+mb_substr_count(): Argument #2 ($needle) must not be empty
int(0)
int(0)
int(0)