Skip to content

Commit d1ed400

Browse files
committed
Deprecated::$message is nullable and needs to be properly initialized.
1 parent 641d96f commit d1ed400

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Zend/tests/attributes/deprecated_002.phpt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,26 @@
33
--FILE--
44
<?php
55

6-
#[Deprecated("use test() instead")]
6+
#[Deprecated()]
77
function test() {
88
}
99

10+
#[Deprecated("use test() instead")]
11+
function test2() {
12+
}
13+
1014
$reflection = new ReflectionFunction('test');
1115
var_dump($reflection->getAttributes()[0]->newInstance());
1216

17+
$reflection = new ReflectionFunction('test2');
18+
var_dump($reflection->getAttributes()[0]->newInstance());
19+
1320
--EXPECTF--
1421
object(Deprecated)#3 (1) {
22+
["message"]=>
23+
NULL
24+
}
25+
object(Deprecated)#2 (1) {
1526
["message"]=>
1627
string(18) "use test() instead"
1728
}

Zend/zend_attributes.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,18 @@ ZEND_METHOD(Attribute, __construct)
9696

9797
ZEND_METHOD(Deprecated, __construct)
9898
{
99-
zend_string *message;
99+
zend_string *message = NULL;
100100

101101
ZEND_PARSE_PARAMETERS_START(0, 1)
102102
Z_PARAM_OPTIONAL
103-
Z_PARAM_STR(message)
103+
Z_PARAM_STR_OR_NULL(message)
104104
ZEND_PARSE_PARAMETERS_END();
105105

106-
ZVAL_STR(OBJ_PROP_NUM(Z_OBJ_P(ZEND_THIS), 0), message);
106+
if (message) {
107+
ZVAL_STR(OBJ_PROP_NUM(Z_OBJ_P(ZEND_THIS), 0), message);
108+
} else {
109+
ZVAL_NULL(OBJ_PROP_NUM(Z_OBJ_P(ZEND_THIS), 0));
110+
}
107111
}
108112

109113
static zend_attribute *get_attribute(HashTable *attributes, zend_string *lcname, uint32_t offset)
@@ -335,7 +339,7 @@ void zend_register_attribute_ce(void)
335339

336340
ZVAL_UNDEF(&tmp);
337341
str = zend_string_init(ZEND_STRL("message"), 1);
338-
zend_declare_typed_property(zend_ce_deprecated_attribute, str, &tmp, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_CODE(IS_STRING, 0, 0));
342+
zend_declare_typed_property(zend_ce_deprecated_attribute, str, &tmp, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_STRING));
339343
zend_string_release(str);
340344

341345
attr = zend_internal_attribute_register(zend_ce_deprecated_attribute, ZEND_ATTRIBUTE_TARGET_FUNCTION | ZEND_ATTRIBUTE_TARGET_METHOD);

0 commit comments

Comments
 (0)