summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-05-29 09:52:43 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-05-29 09:52:43 +0200
commitcf610347a7a44b292b59c3b9855e93b3d204d63e (patch)
tree50d98413185714b9fb0d9731c87c30dbc5488efe
parent7c39ff8ef54cd82c2a9a97ff42e452aab6344d36 (diff)
parent3bd5b83615d47e480840d50fcaab31a5463cb314 (diff)
downloadphp-git-cf610347a7a44b292b59c3b9855e93b3d204d63e.tar.gz
Merge branch 'PHP-7.4'
-rw-r--r--ext/date/php_date.c11
-rw-r--r--ext/date/tests/DatePeriod_properties1.phpt37
-rw-r--r--ext/date/tests/DatePeriod_properties2.phpt46
3 files changed, 93 insertions, 1 deletions
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index edaab75361..e995b45341 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -662,6 +662,7 @@ static zval *date_interval_write_property(zend_object *object, zend_string *memb
static zval *date_interval_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot);
static zval *date_period_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv);
static zval *date_period_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot);
+static zval *date_period_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot);
/* {{{ Module struct */
zend_module_entry date_module_entry = {
@@ -2161,7 +2162,7 @@ static void date_register_classes(void) /* {{{ */
date_object_handlers_period.free_obj = date_object_free_storage_period;
date_object_handlers_period.clone_obj = date_object_clone_period;
date_object_handlers_period.get_properties = date_object_get_properties_period;
- date_object_handlers_period.get_property_ptr_ptr = NULL;
+ date_object_handlers_period.get_property_ptr_ptr = date_period_get_property_ptr_ptr;
date_object_handlers_period.get_gc = date_object_get_gc_period;
date_object_handlers_period.read_property = date_period_read_property;
date_object_handlers_period.write_property = date_period_write_property;
@@ -5284,3 +5285,11 @@ static zval *date_period_write_property(zend_object *object, zend_string *name,
return value;
}
/* }}} */
+
+/* {{{ date_period_get_property_ptr_ptr */
+static zval *date_period_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot)
+{
+ /* Fall back to read_property handler. */
+ return NULL;
+}
+/* }}} */
diff --git a/ext/date/tests/DatePeriod_properties1.phpt b/ext/date/tests/DatePeriod_properties1.phpt
new file mode 100644
index 0000000000..32ede7d218
--- /dev/null
+++ b/ext/date/tests/DatePeriod_properties1.phpt
@@ -0,0 +1,37 @@
+--TEST--
+DatePeriod: Test read only properties
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+
+$start = new DateTime;
+$interval = new DateInterval('P1D');
+$end = new DateTime;
+$period = new DatePeriod($start, $interval, $end);
+
+echo "recurrences: ";
+var_dump($period->recurrences);
+
+echo "include_start_date: ";
+var_dump($period->include_start_date);
+
+echo "start: ";
+var_dump($period->start == $start);
+
+echo "current: ";
+var_dump($period->current);
+
+echo "end: ";
+var_dump($period->end == $end);
+
+echo "interval: ";
+var_dump($period->interval->format("%R%d"));
+?>
+--EXPECT--
+recurrences: int(1)
+include_start_date: bool(true)
+start: bool(true)
+current: NULL
+end: bool(true)
+interval: string(2) "+1"
diff --git a/ext/date/tests/DatePeriod_properties2.phpt b/ext/date/tests/DatePeriod_properties2.phpt
new file mode 100644
index 0000000000..01858e68d4
--- /dev/null
+++ b/ext/date/tests/DatePeriod_properties2.phpt
@@ -0,0 +1,46 @@
+--TEST--
+DatePeriod: Test cannot modify read only properties
+--INI--
+date.timezone=UTC
+--FILE--
+<?php
+
+$period = new DatePeriod(new DateTime, new DateInterval('P1D'), new DateTime);
+
+$properties = [
+ "recurrences",
+ "include_start_date",
+ "start",
+ "current",
+ "end",
+ "interval",
+];
+
+foreach ($properties as $property) {
+ try {
+ $period->$property = "new";
+ } catch (Error $e) {
+ echo $e->getMessage() . "\n";
+ }
+
+ try {
+ $period->$property[] = "extra";
+ } catch (Error $e) {
+ echo $e->getMessage() . "\n";
+ }
+}
+
+?>
+--EXPECT--
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported
+Writing to DatePeriod properties is unsupported
+Retrieval of DatePeriod properties for modification is unsupported