Skip to content

Commit c6d4851

Browse files
committed
Fixed issue with throwing exception on undefined offset.
1 parent 97cd67d commit c6d4851

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/BaseArray.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function offsetGet($offset) {
5454
return $this->container[$offset];
5555
}
5656

57-
return $this->undefinedOffsetAction($this->container, $offset);
57+
return ($this->undefinedOffsetAction)($this->container, $offset);
5858
}
5959

6060
public function offsetSet($offset, $value) {

tests/unit/BaseArrayTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Sevavietl\Arrays\Tests\Unit;
44

55
use Sevavietl\Arrays\BaseArray;
6+
use Sevavietl\Arrays\UndefinedOffsetException;
67

78
class BaseArrayTest extends \TestCase
89
{
@@ -40,4 +41,12 @@ public function instantiationThrowsExceptionDataProvider()
4041
[new \StdClass],
4142
];
4243
}
44+
45+
public function testThrowsExceptionOnUndefinedOffset()
46+
{
47+
$this->expectException(UndefinedOffsetException::class);
48+
49+
$arr = new BaseArray([1, 2, 3]);
50+
$arr[3];
51+
}
4352
}

0 commit comments

Comments
 (0)