diff --git a/UPGRADING b/UPGRADING index 9dbcd594a29a..0cb0f42fc121 100644 --- a/UPGRADING +++ b/UPGRADING @@ -32,6 +32,11 @@ PHP 8.7 UPGRADE NOTES curl_setopt() return false, instead of being silently interpreted as a combination of redirect types. +- Gettext: + . bindtextdomain() now throws a ValueError when $directory is "0", like + textdomain() does for its $domain. It previously treated it as an empty + string and bound the domain to the current directory. + - PDO: . PDOStatement::bindColumn() now throws a ValueError when the column name is not present in the result set. It previously reported the condition diff --git a/ext/gettext/gettext.c b/ext/gettext/gettext.c index c992dfc40e69..2b8bfee7f684 100644 --- a/ext/gettext/gettext.c +++ b/ext/gettext/gettext.c @@ -206,7 +206,11 @@ PHP_FUNCTION(bindtextdomain) RETURN_STRING(btd_result); } - if (ZSTR_LEN(dir) != 0 && !zend_string_equals_literal(dir, "0")) { + if (ZSTR_LEN(dir) != 0) { + if (zend_string_equals_literal(dir, "0")) { + zend_argument_value_error(2, "cannot be zero"); + RETURN_THROWS(); + } if (!VCWD_REALPATH(ZSTR_VAL(dir), dir_name)) { RETURN_FALSE; } diff --git a/ext/gettext/tests/bindtextdomain_dir_zero.phpt b/ext/gettext/tests/bindtextdomain_dir_zero.phpt new file mode 100644 index 000000000000..45f352854316 --- /dev/null +++ b/ext/gettext/tests/bindtextdomain_dir_zero.phpt @@ -0,0 +1,20 @@ +--TEST-- +bindtextdomain() throws a ValueError when the directory is "0" +--EXTENSIONS-- +gettext +--FILE-- +getMessage(), "\n"; +} + +chdir(__DIR__); +var_dump(bindtextdomain('app', '') === realpath(__DIR__)); + +?> +--EXPECT-- +bindtextdomain(): Argument #2 ($directory) cannot be zero +bool(true)