Skip to content

Commit 4b746fc

Browse files
committed
Fixed bug #73730 (textdomain(null) throws in strict mode)
The $text_domain parameter may be NULL, which we have to cater to explicitly with regard to strict_types.
1 parent 3fd08a1 commit 4b746fc

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ PHP NEWS
2121
. Fixed bug #75124 (gdImageGrayScale() may produce colors). (cmb)
2222
. Fixed bug #75139 (libgd/gd_interpolation.c:1786: suspicious if ?). (cmb)
2323

24+
- Gettext:
25+
. Fixed bug #73730 (textdomain(null) throws in strict mode). (cmb)
26+
2427
- Intl:
2528
. Fixed bug #75090 (IntlGregorianCalendar doesn't have constants from parent
2629
class). (tpunt)

ext/gettext/gettext.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@ PHP_MINFO_FUNCTION(php_gettext)
161161
Set the textdomain to "domain". Returns the current domain */
162162
PHP_NAMED_FUNCTION(zif_textdomain)
163163
{
164-
char *domain, *domain_name, *retval;
165-
size_t domain_len;
164+
char *domain = NULL, *domain_name, *retval;
165+
size_t domain_len = 0;
166166

167-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &domain, &domain_len) == FAILURE) {
167+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &domain, &domain_len) == FAILURE) {
168168
return;
169169
}
170170

171171
PHP_GETTEXT_DOMAIN_LENGTH_CHECK
172172

173-
if (strcmp(domain, "") && strcmp(domain, "0")) {
173+
if (domain != NULL && strcmp(domain, "") && strcmp(domain, "0")) {
174174
domain_name = domain;
175175
} else {
176176
domain_name = NULL;

ext/gettext/tests/bug73730.phpt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #73730 (textdomain(null) throws in strict mode)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gettext')) die('skip gettext extension is not available');
6+
?>
7+
--FILE--
8+
<?php
9+
declare(strict_types=1);
10+
11+
var_dump(textdomain(null));
12+
?>
13+
===DONE===
14+
--EXPECT--
15+
string(8) "messages"
16+
===DONE===

0 commit comments

Comments
 (0)