Skip to content

Commit e4dbda9

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

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
@@ -18,6 +18,8 @@ PHP NEWS
1818
an error). (Derick)
1919
. Fixed Unix timestamps in February of the year 0 are misparsed with
2020
@-notation. (LukasGelbmann)
21+
. Fixed bug GH-11310 (__debugInfo does nothing on userland classes extending
22+
Date classes). (Derick)
2123

2224
- DBA:
2325
. 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
@@ -1959,12 +1959,22 @@ static HashTable *date_object_get_properties_for(zend_object *object, zend_prop_
19591959
php_date_obj *dateobj;
19601960

19611961
switch (purpose) {
1962-
case ZEND_PROP_PURPOSE_DEBUG:
19631962
case ZEND_PROP_PURPOSE_SERIALIZE:
19641963
case ZEND_PROP_PURPOSE_VAR_EXPORT:
19651964
case ZEND_PROP_PURPOSE_JSON:
19661965
case ZEND_PROP_PURPOSE_ARRAY_CAST:
19671966
break;
1967+
case ZEND_PROP_PURPOSE_DEBUG: {
1968+
if (object->ce->__debugInfo) {
1969+
int is_temp = 0;
1970+
HashTable *ht = zend_std_get_debug_info(object, &is_temp);
1971+
if (ht && !is_temp) {
1972+
GC_TRY_ADDREF(ht);
1973+
}
1974+
return ht;
1975+
}
1976+
break;
1977+
}
19681978
default:
19691979
return zend_std_get_properties_for(object, purpose);
19701980
}
@@ -2081,12 +2091,22 @@ static HashTable *date_object_get_properties_for_timezone(zend_object *object, z
20812091
php_timezone_obj *tzobj;
20822092

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

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)