Skip to content

RowIterator::prev() should not throw an exception if you go out of bounds #587

@dkarlovi

Description

@dkarlovi

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

RowIterator::prev() not throwing an exception if you go out of bounds.

What is the current behavior?

RowIterator::prev() throwing an exception if you go out of bounds.

What are the steps to reproduce?

I've implemented an RowIterator decorator which allows me to iterate in reverse,
https://github.com/dkarlovi/xls-transmailifier/blob/command/src/Transmailifier/ReverseRowIterator.php#L63

The way current code works, it will throw an exception if you try to go out of bounds:

if ($this->position <= $this->startRow) {
throw new PhpSpreadsheetException("Row is already at the beginning of range ({$this->startRow} - {$this->endRow})");
}

But, how iterators work, they WILL go out of bounds and then call valid(). You can see this by having next() not check if it's out of bounds, it just does.

I believe this to be a bug.

Which versions of PhpSpreadsheet and PHP are affected?

Latest master, as linked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions