diff --git a/ext/standard/html.c b/ext/standard/html.c
index 0c6231d590d88..878c3afe47e71 100644
--- a/ext/standard/html.c
+++ b/ext/standard/html.c
@@ -1320,6 +1320,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);