[php-src] master: Merge branch 'PHP-8.5'

Derick Rethans <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Derick Rethans (derickr)
Date: 2026-07-10T13:39:41+01:00

Commit: https://github.com/php/php-src/commit/b2011f2ea3ff42b54ee772d3f90dbf43b6ecfb7f
Raw diff: https://github.com/php/php-src/commit/b2011f2ea3ff42b54ee772d3f90dbf43b6ecfb7f.diff

Merge branch 'PHP-8.5'

* PHP-8.5:
  Fix GH-11310: __debugInfo does nothing on userland classes extending Date classes (#22655)

Changed paths:
  A  ext/date/tests/bug-gh11310-1.phpt
  A  ext/date/tests/bug-gh11310-2.phpt
  M  NEWS
  M  ext/date/php_date.c


Diff:

diff --git a/NEWS b/NEWS
index 6d8d5df08ed8..ac709587f699 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,8 @@ PHP                                                                        NEWS
   . Fixed Unix timestamps in February of the year 0 are misparsed with
     @-notation. (LukasGelbmann)
   . Fixed bug GH-11368 (idate() doesn't work for the year -1). (Derick)
+  . Fixed bug GH-11310 (__debugInfo does nothing on userland classes extending
+    Date classes). (Derick)
 
 - DBA:
   . Fixed OOB read on malformed length field in dba flatfile handler. (alhudz)
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index e14aef1e0855..c37230c6ca08 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -1958,12 +1958,22 @@ static HashTable *date_object_get_properties_for(zend_object *object, zend_prop_
 	php_date_obj *dateobj;
 
 	switch (purpose) {
-		case ZEND_PROP_PURPOSE_DEBUG:
 		case ZEND_PROP_PURPOSE_SERIALIZE:
 		case ZEND_PROP_PURPOSE_VAR_EXPORT:
 		case ZEND_PROP_PURPOSE_JSON:
 		case ZEND_PROP_PURPOSE_ARRAY_CAST:
 			break;
+		case ZEND_PROP_PURPOSE_DEBUG: {
+			if (object->ce->__debugInfo) {
+				int is_temp = 0;
+				HashTable *ht = zend_std_get_debug_info(object, &is_temp);
+				if (ht && !is_temp) {
+					GC_TRY_ADDREF(ht);
+				}
+				return ht;
+			}
+			break;
+		}
 		default:
 			return zend_std_get_properties_for(object, purpose);
 	}
@@ -2080,12 +2090,22 @@ static HashTable *date_object_get_properties_for_timezone(zend_object *object, z
 	php_timezone_obj *tzobj;
 
 	switch (purpose) {
-		case ZEND_PROP_PURPOSE_DEBUG:
 		case ZEND_PROP_PURPOSE_SERIALIZE:
 		case ZEND_PROP_PURPOSE_VAR_EXPORT:
 		case ZEND_PROP_PURPOSE_JSON:
 		case ZEND_PROP_PURPOSE_ARRAY_CAST:
 			break;
+		case ZEND_PROP_PURPOSE_DEBUG: {
+			if (object->ce->__debugInfo) {
+				int is_temp = 0;
+				HashTable *ht = zend_std_get_debug_info(object, &is_temp);
+				if (ht && !is_temp) {
+					GC_TRY_ADDREF(ht);
+				}
+				return ht;
+			}
+			break;
+		}
 		default:
 			return zend_std_get_properties_for(object, purpose);
 	}
diff --git a/ext/date/tests/bug-gh11310-1.phpt b/ext/date/tests/bug-gh11310-1.phpt
new file mode 100644
index 000000000000..c12b0201294d
--- /dev/null
+++ b/ext/date/tests/bug-gh11310-1.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Bug GH-11310: __debugInfo does nothing on userland classes extending Date classes
+--FILE--
+<?php
+class UDateTime extends DateTime { public function __debugInfo(): array { return ['value' => 'zzz']; } }
+class UDateTimeImmutable extends DateTimeImmutable { public function __debugInfo(): array { return ['value' => 'zzz']; } }
+class UDateTimeZone extends DateTimeZone { public function __debugInfo(): array { return ['value' => 'zzz']; } }
+class UDateInterval extends DateInterval { public function __debugInfo(): array { return ['value' => 'zzz']; } }
+class UDatePeriod extends DatePeriod { public function __debugInfo(): array { return ['value' => 'zzz']; } }
+
+$d = new UDateTime(); var_dump($d);
+$d = new UDateTimeImmutable(); var_dump($d);
+$d = new UDateTimeZone("Europe/Kyiv"); var_dump($d);
+$d = new UDateInterval("P3D"); var_dump($d);
+$d = UDatePeriod::createFromISO8601String("2026-07-09T17:23:06Z/P3D/R5"); var_dump($d);
+?>
+--EXPECTF--
+object(UDateTime)#%d (1) {
+  ["value"]=>
+  string(3) "zzz"
+}
+object(UDateTimeImmutable)#%d (1) {
+  ["value"]=>
+  string(3) "zzz"
+}
+object(UDateTimeZone)#%d (1) {
+  ["value"]=>
+  string(3) "zzz"
+}
+object(UDateInterval)#%d (1) {
+  ["value"]=>
+  string(3) "zzz"
+}
+object(UDatePeriod)#%d (1) {
+  ["value"]=>
+  string(3) "zzz"
+}
diff --git a/ext/date/tests/bug-gh11310-2.phpt b/ext/date/tests/bug-gh11310-2.phpt
new file mode 100644
index 000000000000..8dce510a19d6
--- /dev/null
+++ b/ext/date/tests/bug-gh11310-2.phpt
@@ -0,0 +1,37 @@
+--TEST--
+Bug GH-11310: __debugInfo does nothing on userland classes extending Date classes
+--FILE--
+<?php
+class UDateTime extends DateTime { public function __construct() {} public function __debugInfo(): array { return ['value' => 'zzz']; } }
+class UDateTimeImmutable extends DateTimeImmutable { public function __construct() {} public function __debugInfo(): array { return ['value' => 'zzz']; } }
+class UDateTimeZone extends DateTimeZone { public function __construct() {} public function __debugInfo(): array { return ['value' => 'zzz']; } }
+class UDateInterval extends DateInterval { public function __construct() {} public function __debugInfo(): array { return ['value' => 'zzz']; } }
+class UDatePeriod extends DatePeriod { public function __construct() {} public function __debugInfo(): array { return ['value' => 'zzz']; } }
+
+$d = new UDateTime(); var_dump($d);
+$d = new UDateTimeImmutable(); var_dump($d);
+$d = new UDateTimeZone("Europe/Kyiv"); var_dump($d);
+$d = new UDateInterval("P3D"); var_dump($d);
+$d = UDatePeriod::createFromISO8601String("2026-07-09T17:23:06Z/P3D/R5"); var_dump($d);
+?>
+--EXPECTF--
+object(UDateTime)#%d (1) {
+  ["value"]=>
+  string(3) "zzz"
+}
+object(UDateTimeImmutable)#%d (1) {
+  ["value"]=>
+  string(3) "zzz"
+}
+object(UDateTimeZone)#%d (1) {
+  ["value"]=>
+  string(3) "zzz"
+}
+object(UDateInterval)#%d (1) {
+  ["value"]=>
+  string(3) "zzz"
+}
+object(UDatePeriod)#%d (1) {
+  ["value"]=>
+  string(3) "zzz"
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.