diff --git a/ext/standard/html.c b/ext/standard/html.c
index 4d1e8ab4987..af6e6ec9444 100644
--- a/ext/standard/html.c
+++ b/ext/standard/html.c
@@ -1356,6 +1356,9 @@ static void php_html_entities(INTERNAL_FUNCTION_PARAMETERS, int all)
Z_PARAM_BOOL(double_encode);
ZEND_PARSE_PARAMETERS_END();
+ if (ZSTR_LEN(str) == 0) {
+ RETURN_EMPTY_STRING();
+ }
replaced = php_escape_html_entities_ex(
(unsigned char*)ZSTR_VAL(str), ZSTR_LEN(str), all, (int) flags,
hint_charset ? ZSTR_VAL(hint_charset) : NULL, double_encode, /* quiet */ 0);