Skip to content

Commit dff201b

Browse files
committed
Ensure the internal properties cannot be overwritten
1 parent 735ca22 commit dff201b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

ext/date/php_date.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5279,7 +5279,12 @@ static zval *date_period_read_property(zval *object, zval *member, int type, voi
52795279
/* {{{ date_period_write_property */
52805280
static void date_period_write_property(zval *object, zval *member, zval *value, void **cache_slot)
52815281
{
5282-
zend_throw_error(NULL, "Writing to DatePeriod properties is unsupported");
5282+
if (!std_object_handlers.has_property(object, member, 2, NULL)) {
5283+
zend_throw_error(NULL, "Writing to DatePeriod->%s is unsupported", ZSTR_VAL(zval_get_string(member)));
5284+
return;
5285+
}
5286+
5287+
std_object_handlers.write_property(object, member, value, cache_slot);
52835288
}
52845289
/* }}} */
52855290

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
DatePeriod: Test cannot modify read only properties
3+
--INI--
4+
date.timezone=UTC
5+
--FILE--
6+
<?php
7+
8+
$period = new DatePeriod(new DateTime, new DateInterval('P1D'), new DateTime);
9+
10+
$properties = [
11+
"recurrences",
12+
"include_start_date",
13+
"start",
14+
"current",
15+
"end",
16+
"interval",
17+
];
18+
19+
foreach ($properties as $property) {
20+
try {
21+
var_dump($period->$property = "new");
22+
} catch (Error $e) {
23+
echo $e->getMessage() . "\n";
24+
}
25+
}
26+
27+
?>
28+
--EXPECT--
29+
Writing to DatePeriod->recurrences is unsupported
30+
Writing to DatePeriod->include_start_date is unsupported
31+
Writing to DatePeriod->start is unsupported
32+
Writing to DatePeriod->current is unsupported
33+
Writing to DatePeriod->end is unsupported
34+
Writing to DatePeriod->interval is unsupported

0 commit comments

Comments
 (0)