Skip to content

Commit 176d285

Browse files
committed
Add DatePeriod has property handler
1 parent a316fa1 commit 176d285

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

ext/date/php_date.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ static int date_interval_compare_objects(zval *o1, zval *o2);
360360
static zval *date_interval_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv);
361361
static zval *date_interval_write_property(zend_object *object, zend_string *member, zval *value, void **cache_slot);
362362
static zval *date_interval_get_property_ptr_ptr(zend_object *object, zend_string *member, int type, void **cache_slot);
363+
static int date_period_has_property(zend_object *object, zend_string *name, int type, void **cache_slot);
363364
static zval *date_period_read_property(zend_object *object, zend_string *name, int type, void **cache_slot, zval *rv);
364365
static zval *date_period_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot);
365366
static zval *date_period_get_property_ptr_ptr(zend_object *object, zend_string *name, int type, void **cache_slot);
@@ -1796,6 +1797,7 @@ static void date_register_classes(void) /* {{{ */
17961797
date_object_handlers_period.clone_obj = date_object_clone_period;
17971798
date_object_handlers_period.get_gc = date_object_get_gc_period;
17981799
date_object_handlers_period.get_property_ptr_ptr = date_period_get_property_ptr_ptr;
1800+
date_object_handlers_period.has_property = date_period_has_property;
17991801
date_object_handlers_period.read_property = date_period_read_property;
18001802
date_object_handlers_period.write_property = date_period_write_property;
18011803
date_object_handlers_period.get_properties_for = date_period_get_properties_for;
@@ -5926,6 +5928,44 @@ PHP_METHOD(DatePeriod, __wakeup)
59265928
}
59275929
/* }}} */
59285930

5931+
static int date_period_has_property(zend_object *object, zend_string *name, int type, void **cache_slot)
5932+
{
5933+
zval rv;
5934+
zval *prop;
5935+
5936+
if (!date_period_is_internal_property(name)) {
5937+
return zend_std_has_property(object, name, type, cache_slot);
5938+
}
5939+
5940+
php_period_obj *period_obj = php_period_obj_from_obj(object);
5941+
if (!period_obj->initialized) {
5942+
switch (type) {
5943+
case ZEND_PROPERTY_ISSET: /* Intentional fallthrough */
5944+
case ZEND_PROPERTY_NOT_EMPTY:
5945+
return 0;
5946+
case ZEND_PROPERTY_EXISTS:
5947+
return 1;
5948+
default:
5949+
ZEND_UNREACHABLE();
5950+
break;
5951+
}
5952+
}
5953+
5954+
if (type == ZEND_PROPERTY_EXISTS) {
5955+
return 1;
5956+
}
5957+
5958+
prop = date_period_read_property(object, name, BP_VAR_IS, cache_slot, &rv);
5959+
ZEND_ASSERT(prop != &EG(uninitialized_zval));
5960+
5961+
if (type == ZEND_PROPERTY_NOT_EMPTY) {
5962+
return zend_is_true(prop);
5963+
}
5964+
5965+
ZEND_ASSERT(type == ZEND_PROPERTY_ISSET);
5966+
return (Z_TYPE_P(prop) != IS_NULL);
5967+
}
5968+
59295969
/* {{{ date_period_read_property */
59305970
static zval *date_period_read_property(zend_object *object, zend_string *name, int type, void **cache_slot, zval *rv)
59315971
{
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
Test isset on DatePeriod instantiated without its constructor
3+
--FILE--
4+
<?php
5+
6+
class MyDatePeriod extends DatePeriod {
7+
public int $my;
8+
}
9+
10+
$rc = new ReflectionClass('MyDatePeriod');
11+
$di = $rc->newInstanceWithoutConstructor();
12+
13+
var_dump(isset($di->start));
14+
var_dump(empty($di->start));
15+
var_dump(property_exists($di, "start"));
16+
17+
var_dump(isset($di->recurrences));
18+
var_dump(empty($di->recurrences));
19+
var_dump(property_exists($di, "recurrences"));
20+
21+
var_dump(isset($di->end));
22+
var_dump(empty($di->end));
23+
var_dump(property_exists($di, "end"));
24+
25+
var_dump(isset($di->my));
26+
var_dump(empty($di->my));
27+
var_dump(property_exists($di, "my"));
28+
29+
?>
30+
--EXPECT--
31+
bool(false)
32+
bool(true)
33+
bool(true)
34+
bool(false)
35+
bool(true)
36+
bool(true)
37+
bool(false)
38+
bool(true)
39+
bool(true)
40+
bool(false)
41+
bool(true)
42+
bool(true)

0 commit comments

Comments
 (0)