[php-src] Issue #9401: Iterating over DatePeriod doesn't return custom date/time class anymore

From: Date: Mon, 22 Aug 2022 14:00:55 +0000
Subject: [php-src] Issue #9401: Iterating over DatePeriod doesn't return custom date/time class anymore
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242286@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9401
Author: rimace

### Description

The following code:

```php
<?php
class CustomDateTime extends \DateTime
{ }

$begin = new CustomDateTime('2012-08-01');
$end = new CustomDateTime('2012-08-31');
$period = new \DatePeriod($begin, new \DateInterval('P1D'), $end);
	
foreach ($period as $day) {
	echo get_class($day);
	exit;
}
```

Resulted in this output:
```
DateTime
```

But I expected this output instead:
```
CustomDateTime
```


This change in behaviour was introduced with a bug-fix release 8.1.9. It worked with 8.1.7.


### PHP Version

PHP 8.1.9

### Operating System

Windows + Ubuntu


Thread (1 message)

  • rimace
« previous php.bugs (#242286) next »