Skip to content

Commit b360cf8

Browse files
ext/hash: Add #[\Deprecated] to MHASH_* constants (#19565)
1 parent 948ab10 commit b360cf8

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

ext/hash/hash.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,15 +1178,26 @@ static void mhash_init(INIT_FUNC_ARGS)
11781178
int len;
11791179
int algo_number = 0;
11801180

1181+
zend_string *deprecation_reason = zend_string_init("as the mhash*() functions were deprecated", strlen("as the mhash*() functions were deprecated"), 1);
11811182
for (algo_number = 0; algo_number < MHASH_NUM_ALGOS; algo_number++) {
11821183
struct mhash_bc_entry algorithm = mhash_to_hash[algo_number];
11831184
if (algorithm.mhash_name == NULL) {
11841185
continue;
11851186
}
11861187

11871188
len = slprintf(buf, 127, "MHASH_%s", algorithm.mhash_name);
1188-
zend_register_long_constant(buf, len, algorithm.value, CONST_PERSISTENT|CONST_DEPRECATED, module_number);
1189-
}
1189+
zend_constant *mhash_const = zend_register_long_constant(buf, len, algorithm.value, CONST_PERSISTENT|CONST_DEPRECATED, module_number);
1190+
1191+
zend_attribute *deprecation_attrib = zend_add_global_constant_attribute(mhash_const, ZSTR_KNOWN(ZEND_STR_DEPRECATED_CAPITALIZED), 2);
1192+
ZVAL_STR(&deprecation_attrib->args[0].value, ZSTR_KNOWN(ZEND_STR_8_DOT_5));
1193+
deprecation_attrib->args[0].name = ZSTR_KNOWN(ZEND_STR_SINCE);
1194+
ZVAL_STR_COPY(&deprecation_attrib->args[1].value, deprecation_reason);
1195+
deprecation_attrib->args[1].name = ZSTR_KNOWN(ZEND_STR_MESSAGE);
1196+
}
1197+
/* Each of the attributes uses ZVAL_STR_COPY instead of trying to special
1198+
* case one of them to use ZVAL_STR, but that means there is one more
1199+
* reference that needs to be decremented. */
1200+
zend_string_release(deprecation_reason);
11901201

11911202
/* TODO: this cause #69823 zend_register_internal_module(&mhash_module_entry); */
11921203
}

ext/hash/tests/mhash_001.phpt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,77 +35,77 @@ foreach ($supported_hash_al as $hash=>$wanted) {
3535
}
3636
?>
3737
--EXPECTF--
38-
Deprecated: Constant MHASH_MD5 is deprecated in %s on line %d
38+
Deprecated: Constant MHASH_MD5 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
3939

4040
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d
4141
MHASH_MD5
4242
ok
4343

4444

45-
Deprecated: Constant MHASH_SHA1 is deprecated in %s on line %d
45+
Deprecated: Constant MHASH_SHA1 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
4646

4747
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d
4848
MHASH_SHA1
4949
ok
5050

5151

52-
Deprecated: Constant MHASH_HAVAL256 is deprecated in %s on line %d
52+
Deprecated: Constant MHASH_HAVAL256 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
5353

5454
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d
5555
MHASH_HAVAL256
5656
ok
5757

5858

59-
Deprecated: Constant MHASH_HAVAL192 is deprecated in %s on line %d
59+
Deprecated: Constant MHASH_HAVAL192 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
6060

6161
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d
6262
MHASH_HAVAL192
6363
ok
6464

6565

66-
Deprecated: Constant MHASH_HAVAL224 is deprecated in %s on line %d
66+
Deprecated: Constant MHASH_HAVAL224 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
6767

6868
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d
6969
MHASH_HAVAL224
7070
ok
7171

7272

73-
Deprecated: Constant MHASH_HAVAL160 is deprecated in %s on line %d
73+
Deprecated: Constant MHASH_HAVAL160 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
7474

7575
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d
7676
MHASH_HAVAL160
7777
ok
7878

7979

80-
Deprecated: Constant MHASH_RIPEMD160 is deprecated in %s on line %d
80+
Deprecated: Constant MHASH_RIPEMD160 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
8181

8282
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d
8383
MHASH_RIPEMD160
8484
ok
8585

8686

87-
Deprecated: Constant MHASH_GOST is deprecated in %s on line %d
87+
Deprecated: Constant MHASH_GOST is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
8888

8989
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d
9090
MHASH_GOST
9191
ok
9292

9393

94-
Deprecated: Constant MHASH_TIGER is deprecated in %s on line %d
94+
Deprecated: Constant MHASH_TIGER is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
9595

9696
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d
9797
MHASH_TIGER
9898
ok
9999

100100

101-
Deprecated: Constant MHASH_CRC32 is deprecated in %s on line %d
101+
Deprecated: Constant MHASH_CRC32 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
102102

103103
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d
104104
MHASH_CRC32
105105
ok
106106

107107

108-
Deprecated: Constant MHASH_CRC32B is deprecated in %s on line %d
108+
Deprecated: Constant MHASH_CRC32B is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
109109

110110
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d
111111
MHASH_CRC32B

ext/hash/tests/mhash_003.phpt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,77 +35,77 @@ foreach ($supported_hash_al as $hash=>$wanted) {
3535
}
3636
?>
3737
--EXPECTF--
38-
Deprecated: Constant MHASH_MD5 is deprecated in %s on line %d
38+
Deprecated: Constant MHASH_MD5 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
3939

4040
Deprecated: Function mhash_keygen_s2k() is deprecated since 8.1 in %s on line %d
4141
MHASH_MD5
4242
ok
4343

4444

45-
Deprecated: Constant MHASH_SHA1 is deprecated in %s on line %d
45+
Deprecated: Constant MHASH_SHA1 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
4646

4747
Deprecated: Function mhash_keygen_s2k() is deprecated since 8.1 in %s on line %d
4848
MHASH_SHA1
4949
ok
5050

5151

52-
Deprecated: Constant MHASH_HAVAL256 is deprecated in %s on line %d
52+
Deprecated: Constant MHASH_HAVAL256 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
5353

5454
Deprecated: Function mhash_keygen_s2k() is deprecated since 8.1 in %s on line %d
5555
MHASH_HAVAL256
5656
ok
5757

5858

59-
Deprecated: Constant MHASH_HAVAL224 is deprecated in %s on line %d
59+
Deprecated: Constant MHASH_HAVAL224 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
6060

6161
Deprecated: Function mhash_keygen_s2k() is deprecated since 8.1 in %s on line %d
6262
MHASH_HAVAL224
6363
ok
6464

6565

66-
Deprecated: Constant MHASH_HAVAL192 is deprecated in %s on line %d
66+
Deprecated: Constant MHASH_HAVAL192 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
6767

6868
Deprecated: Function mhash_keygen_s2k() is deprecated since 8.1 in %s on line %d
6969
MHASH_HAVAL192
7070
ok
7171

7272

73-
Deprecated: Constant MHASH_HAVAL160 is deprecated in %s on line %d
73+
Deprecated: Constant MHASH_HAVAL160 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
7474

7575
Deprecated: Function mhash_keygen_s2k() is deprecated since 8.1 in %s on line %d
7676
MHASH_HAVAL160
7777
ok
7878

7979

80-
Deprecated: Constant MHASH_RIPEMD160 is deprecated in %s on line %d
80+
Deprecated: Constant MHASH_RIPEMD160 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
8181

8282
Deprecated: Function mhash_keygen_s2k() is deprecated since 8.1 in %s on line %d
8383
MHASH_RIPEMD160
8484
ok
8585

8686

87-
Deprecated: Constant MHASH_GOST is deprecated in %s on line %d
87+
Deprecated: Constant MHASH_GOST is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
8888

8989
Deprecated: Function mhash_keygen_s2k() is deprecated since 8.1 in %s on line %d
9090
MHASH_GOST
9191
ok
9292

9393

94-
Deprecated: Constant MHASH_TIGER is deprecated in %s on line %d
94+
Deprecated: Constant MHASH_TIGER is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
9595

9696
Deprecated: Function mhash_keygen_s2k() is deprecated since 8.1 in %s on line %d
9797
MHASH_TIGER
9898
ok
9999

100100

101-
Deprecated: Constant MHASH_CRC32 is deprecated in %s on line %d
101+
Deprecated: Constant MHASH_CRC32 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
102102

103103
Deprecated: Function mhash_keygen_s2k() is deprecated since 8.1 in %s on line %d
104104
MHASH_CRC32
105105
ok
106106

107107

108-
Deprecated: Constant MHASH_CRC32B is deprecated in %s on line %d
108+
Deprecated: Constant MHASH_CRC32B is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
109109

110110
Deprecated: Function mhash_keygen_s2k() is deprecated since 8.1 in %s on line %d
111111
MHASH_CRC32B

ext/hash/tests/mhash_004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var_dump($algo);
1212

1313
?>
1414
--EXPECTF--
15-
Deprecated: Constant MHASH_MD5 is deprecated in %s on line %d
15+
Deprecated: Constant MHASH_MD5 is deprecated since 8.5, as the mhash*() functions were deprecated in %s on line %d
1616
int(1)
1717

1818
Deprecated: Function mhash() is deprecated since 8.1 in %s on line %d

0 commit comments

Comments
 (0)