Skip to content

Commit b2011f2

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-11310: __debugInfo does nothing on userland classes extending Date classes (#22655)
2 parents d1d144e + e4dbda9 commit b2011f2

4 files changed

Lines changed: 98 additions & 2 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ PHP NEWS
2121
. Fixed Unix timestamps in February of the year 0 are misparsed with
2222
@-notation. (LukasGelbmann)
2323
. Fixed bug GH-11368 (idate() doesn't work for the year -1). (Derick)
24+
. Fixed bug GH-11310 (__debugInfo does nothing on userland classes extending
25+
Date classes). (Derick)
2426

2527
- DBA:
2628
. Fixed OOB read on malformed length field in dba flatfile handler. (alhudz)

ext/date/php_date.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,12 +1958,22 @@ static HashTable *date_object_get_properties_for(zend_object *object, zend_prop_
19581958
php_date_obj *dateobj;
19591959

19601960
switch (purpose) {
1961-
case ZEND_PROP_PURPOSE_DEBUG:
19621961
case ZEND_PROP_PURPOSE_SERIALIZE:
19631962
case ZEND_PROP_PURPOSE_VAR_EXPORT:
19641963
case ZEND_PROP_PURPOSE_JSON:
19651964
case ZEND_PROP_PURPOSE_ARRAY_CAST:
19661965
break;
1966+
case ZEND_PROP_PURPOSE_DEBUG: {
1967+
if (object->ce->__debugInfo) {
1968+
int is_temp = 0;
1969+
HashTable *ht = zend_std_get_debug_info(object, &is_temp);
1970+
if (ht && !is_temp) {
1971+
GC_TRY_ADDREF(ht);
1972+
}
1973+
return ht;
1974+
}
1975+
break;
1976+
}
19671977
default:
19681978
return zend_std_get_properties_for(object, purpose);
19691979
}
@@ -2080,12 +2090,22 @@ static HashTable *date_object_get_properties_for_timezone(zend_object *object, z
20802090
php_timezone_obj *tzobj;
20812091

20822092
switch (purpose) {
2083-
case ZEND_PROP_PURPOSE_DEBUG:
20842093
case ZEND_PROP_PURPOSE_SERIALIZE:
20852094
case ZEND_PROP_PURPOSE_VAR_EXPORT:
20862095
case ZEND_PROP_PURPOSE_JSON:
20872096
case ZEND_PROP_PURPOSE_ARRAY_CAST:
20882097
break;
2098+
case ZEND_PROP_PURPOSE_DEBUG: {
2099+
if (object->ce->__debugInfo) {
2100+
int is_temp = 0;
2101+
HashTable *ht = zend_std_get_debug_info(object, &is_temp);
2102+
if (ht && !is_temp) {
2103+
GC_TRY_ADDREF(ht);
2104+
}
2105+
return ht;
2106+
}
2107+
break;
2108+
}
20892109
default:
20902110
return zend_std_get_properties_for(object, purpose);
20912111
}

ext/date/tests/bug-gh11310-1.phpt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Bug GH-11310: __debugInfo does nothing on userland classes extending Date classes
3+
--FILE--
4+
<?php
5+
class UDateTime extends DateTime { public function __debugInfo(): array { return ['value' => 'zzz']; } }
6+
class UDateTimeImmutable extends DateTimeImmutable { public function __debugInfo(): array { return ['value' => 'zzz']; } }
7+
class UDateTimeZone extends DateTimeZone { public function __debugInfo(): array { return ['value' => 'zzz']; } }
8+
class UDateInterval extends DateInterval { public function __debugInfo(): array { return ['value' => 'zzz']; } }
9+
class UDatePeriod extends DatePeriod { public function __debugInfo(): array { return ['value' => 'zzz']; } }
10+
11+
$d = new UDateTime(); var_dump($d);
12+
$d = new UDateTimeImmutable(); var_dump($d);
13+
$d = new UDateTimeZone("Europe/Kyiv"); var_dump($d);
14+
$d = new UDateInterval("P3D"); var_dump($d);
15+
$d = UDatePeriod::createFromISO8601String("2026-07-09T17:23:06Z/P3D/R5"); var_dump($d);
16+
?>
17+
--EXPECTF--
18+
object(UDateTime)#%d (1) {
19+
["value"]=>
20+
string(3) "zzz"
21+
}
22+
object(UDateTimeImmutable)#%d (1) {
23+
["value"]=>
24+
string(3) "zzz"
25+
}
26+
object(UDateTimeZone)#%d (1) {
27+
["value"]=>
28+
string(3) "zzz"
29+
}
30+
object(UDateInterval)#%d (1) {
31+
["value"]=>
32+
string(3) "zzz"
33+
}
34+
object(UDatePeriod)#%d (1) {
35+
["value"]=>
36+
string(3) "zzz"
37+
}

ext/date/tests/bug-gh11310-2.phpt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Bug GH-11310: __debugInfo does nothing on userland classes extending Date classes
3+
--FILE--
4+
<?php
5+
class UDateTime extends DateTime { public function __construct() {} public function __debugInfo(): array { return ['value' => 'zzz']; } }
6+
class UDateTimeImmutable extends DateTimeImmutable { public function __construct() {} public function __debugInfo(): array { return ['value' => 'zzz']; } }
7+
class UDateTimeZone extends DateTimeZone { public function __construct() {} public function __debugInfo(): array { return ['value' => 'zzz']; } }
8+
class UDateInterval extends DateInterval { public function __construct() {} public function __debugInfo(): array { return ['value' => 'zzz']; } }
9+
class UDatePeriod extends DatePeriod { public function __construct() {} public function __debugInfo(): array { return ['value' => 'zzz']; } }
10+
11+
$d = new UDateTime(); var_dump($d);
12+
$d = new UDateTimeImmutable(); var_dump($d);
13+
$d = new UDateTimeZone("Europe/Kyiv"); var_dump($d);
14+
$d = new UDateInterval("P3D"); var_dump($d);
15+
$d = UDatePeriod::createFromISO8601String("2026-07-09T17:23:06Z/P3D/R5"); var_dump($d);
16+
?>
17+
--EXPECTF--
18+
object(UDateTime)#%d (1) {
19+
["value"]=>
20+
string(3) "zzz"
21+
}
22+
object(UDateTimeImmutable)#%d (1) {
23+
["value"]=>
24+
string(3) "zzz"
25+
}
26+
object(UDateTimeZone)#%d (1) {
27+
["value"]=>
28+
string(3) "zzz"
29+
}
30+
object(UDateInterval)#%d (1) {
31+
["value"]=>
32+
string(3) "zzz"
33+
}
34+
object(UDatePeriod)#%d (1) {
35+
["value"]=>
36+
string(3) "zzz"
37+
}

0 commit comments

Comments
 (0)