Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fc1b826

Browse files
committed
Allow incrementing offsets in a collection.
Signed-off-by: Jason Lewis <[email protected]>
1 parent 4612d11 commit fc1b826

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/Illuminate/Support/Collection.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,14 @@ public function offsetGet($key)
251251
*/
252252
public function offsetSet($key, $value)
253253
{
254-
$this->items[$key] = $value;
254+
if(is_null($key))
255+
{
256+
$this->items[] = $value;
257+
}
258+
else
259+
{
260+
$this->items[$key] = $value;
261+
}
255262
}
256263

257264
/**

tests/Support/SupportCollectionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public function testOffsetAccess()
8686
$this->assertTrue(isset($c['name']));
8787
unset($c['name']);
8888
$this->assertFalse(isset($c['name']));
89+
$c[] = 'jason';
90+
$this->assertEquals('jason', $c[0]);
8991
}
9092

9193

0 commit comments

Comments
 (0)