-
-
Notifications
You must be signed in to change notification settings - Fork 637
Deprecated warnings for incompatible return types in PHP 8.1 #846
Comments
Please send a PR, this is the only way to fix the issue |
Hi! Feel free to send a PR :) Just one thing: if you take a look at the
As you can see, the PHPDoc is correct. To solve the issue you mentioned, the correct fix would be to add a proper return type (instead of adding the |
Adding the return type would break backward compatibility and assuming that this fix would get released as a patch version, I am not sure this would be the best solution. If this is not a concern, however, I can certainly PR accordingly. |
Well most of the methods are (or should be considered) internal only. So adding a return type should not break anybody. |
Well, you could get a break even with a correct return type because adding explicit return types forces all extending classes to have explicit return types as well, otherwise PHP will raise a fatal error (function interface mismatch). class RowIterator implements IteratorInterface
{
/**
* Rewind the Iterator to the first element
* @see http://php.net/manual/en/iterator.rewind.php
*/
public function rewind(): void
{
...
}
} then an overridden function with the current interface in an extending class class MyIterator extends RowIterator
{
/**
* Rewind the Iterator to the first element
* @see http://php.net/manual/en/iterator.rewind.php
*
* @return void
*/
public function rewind()
{
...
}
} would cause a break. |
Please let me know whether you prefer the addition of explicit return types (despite possible breaks) or want it to be solved with attributes. |
@fabacino As part of another PR, I fixed these issues (using explicit types) |
Since PHP 8.1 most methods of internal classes require a compatible return type when overriding them (see Return Type Compatibility with Internal Classes).
This results in deprecated warnings for the following classes:
Box\Spout\Reader\CSV\RowIterator
Box\Spout\Reader\CSV\SheetIterator
Box\Spout\Reader\ODS\RowIterator
Box\Spout\Reader\ODS\SheetIterator
Box\Spout\Reader\Wrapper\XMLReader
Box\Spout\Reader\XLSX\RowIterator
Box\Spout\Reader\XLSX\SheetIterator
Sample output for
Box\Spout\Reader\CSV\RowIterator
:Adding the
#[\ReturnTypeWillChange]
attribute to these methods fixes the issue. I can PR if appreciated.The text was updated successfully, but these errors were encountered: