[php-src] Issue #8192: Cannot override DirectoryIterator::current() in 8.1
| From: | zerocrates | Date: | Fri, 11 Mar 2022 23:43:49 +0000 |
| Subject: | [php-src] Issue #8192: Cannot override DirectoryIterator::current() in 8.1 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240307@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8192
Author: zerocrates
### Description
The following code:
```php
<?php
class OverrideValidDirectoryIterator extends DirectoryIterator {
public function valid() {
return null;
}
}
class OverrideCurrentDirectoryIterator extends DirectoryIterator {
public function current() {
return null;
}
}
```
Resulted in this output:
```
Deprecated: Return type of OverrideValidDirectoryIterator::valid() should either be compatible with
DirectoryIterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to
temporarily suppress the notice in /in/S7tkM on line 4
Fatal error: Declaration of OverrideCurrentDirectoryIterator::current() must be compatible with
DirectoryIterator::current(): mixed in /in/S7tkM on line 10
```
Obviously the first here is just a form of the documented 8.1 deprecation of overriding core classes
without matching return typehints, but unlike for other methods on DirectoryIterator, overriding
current() in this way is a fatal error and not an E_DEPRECATED, and the
ReturnTypeWillChange attribute has no effect.
### PHP Version
PHP 8.1.3
### Operating System
_No response_