Skip to content

Commit 24aeeea

Browse files
committed
Ensure that the Deprecated::$message property is treated as readonly by Deprecated::__construct()
1 parent e6c3a6c commit 24aeeea

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
#[Deprecated]’s $message property is readonly.
3+
--FILE--
4+
<?php
5+
6+
$d = new Deprecated("foo");
7+
$d->__construct("bar");
8+
9+
?>
10+
--EXPECTF--
11+
Fatal error: Uncaught Error: Cannot modify readonly property Deprecated::$message in %s:%d
12+
Stack trace:
13+
#0 %s(%d): Deprecated->__construct('bar')
14+
#1 {main}
15+
thrown in %s on line %d

Zend/zend_attributes.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,20 @@ ZEND_METHOD(Override, __construct)
172172
ZEND_METHOD(Deprecated, __construct)
173173
{
174174
zend_string *message = NULL;
175+
zval value;
176+
177+
ZVAL_NULL(&value);
175178

176179
ZEND_PARSE_PARAMETERS_START(0, 1)
177180
Z_PARAM_OPTIONAL
178181
Z_PARAM_STR_OR_NULL(message)
179182
ZEND_PARSE_PARAMETERS_END();
180183

181184
if (message) {
182-
ZVAL_STR(OBJ_PROP_NUM(Z_OBJ_P(ZEND_THIS), 0), message);
183-
} else {
184-
ZVAL_NULL(OBJ_PROP_NUM(Z_OBJ_P(ZEND_THIS), 0));
185+
ZVAL_STR(&value, message);
185186
}
187+
188+
zend_update_property_ex(zend_ce_deprecated_attribute, Z_OBJ_P(ZEND_THIS), ZSTR_KNOWN(ZEND_STR_MESSAGE), &value);
186189
}
187190

188191
static zend_attribute *get_attribute(HashTable *attributes, zend_string *lcname, uint32_t offset)

0 commit comments

Comments
 (0)