Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ PHP NEWS
an error). (Derick)
. Fixed Unix timestamps in February of the year 0 are misparsed with
@-notation. (LukasGelbmann)
. 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)
Expand Down
24 changes: 22 additions & 2 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -1995,12 +1995,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);
}
Expand Down Expand Up @@ -2117,12 +2127,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);
}
Expand Down
37 changes: 37 additions & 0 deletions ext/date/tests/bug-gh11310-1.phpt
Original file line number Diff line number Diff line change
@@ -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']; } }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also add cases where the parent constructor is not called, to ensure that the parent constructor isn't doing any initialization that is required for the overrides to work?

and at least one case of calling parent::__debugInfo() and confirming that the parent info still shows up

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried adding a test with calling parent::_debugInfo(), but none of the classes have a __debugInfo() method, so that would just be testing calling an undefined method.

I've added tests for when the ctor of the original classes isn't called.

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"
}
37 changes: 37 additions & 0 deletions ext/date/tests/bug-gh11310-2.phpt
Original file line number Diff line number Diff line change
@@ -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"
}
Loading