-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Request #48358 insertBeforeOffset() and insertAfterOffset() methods for ... #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0129116
Request #48358 insertBeforeOffset() and insertAfterOffset() methods f…
0fb7e5c
Fix #48358 insertBeforeOffset() and insertAfterOffset() methods for S…
ccc3bcb
Fix #48358 insertBeforeOffset() and insertAfterOffset() methods for S…
c7268b1
Fix #48358 insertBeforeOffset() and insertAfterOffset() methods for S…
39e785e
Fix #48358 add() method for SplDoublyLinkedList
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--TEST-- | ||
Check that SplDoublyLinkedList::add throws an exception with an invalid offset argument | ||
--FILE-- | ||
<?php | ||
try { | ||
$dll = new SplDoublyLinkedList(); | ||
var_dump($dll->add(12,'Offset 12 should not exist')); | ||
} catch (OutOfRangeException $e) { | ||
echo "Exception: ".$e->getMessage()."\n"; | ||
} | ||
?> | ||
--EXPECTF-- | ||
Exception: Offset invalid or out of range |
11 changes: 11 additions & 0 deletions
11
ext/spl/tests/SplDoublyLinkedList_add_missing_parameter1.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--TEST-- | ||
Check that SplDoublyLinkedList::add generate a warning and returns a NULL with missing arguments | ||
--FILE-- | ||
<?php | ||
$dll = new SplDoublyLinkedList(); | ||
var_dump($dll->add()); | ||
?> | ||
--EXPECTF-- | ||
Warning: SplDoublyLinkedList::add() expects exactly 2 parameters, 0 given in %s on line %d | ||
NULL | ||
|
11 changes: 11 additions & 0 deletions
11
ext/spl/tests/SplDoublyLinkedList_add_missing_parameter2.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--TEST-- | ||
Check that SplDoublyLinkedList::add generate a warning and returns a NULL with a missing value argument | ||
--FILE-- | ||
<?php | ||
$dll = new SplDoublyLinkedList(); | ||
var_dump($dll->add(2)); | ||
?> | ||
--EXPECTF-- | ||
Warning: SplDoublyLinkedList::add() expects exactly 2 parameters, 1 given in %s on line %d | ||
NULL | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--TEST-- | ||
Check that SplDoublyLinkedList::add throws an exception with an invalid offset argument | ||
--FILE-- | ||
<?php | ||
try { | ||
$dll = new SplDoublyLinkedList(); | ||
var_dump($dll->add(NULL,2)); | ||
} catch (OutOfRangeException $e) { | ||
echo "Exception: ".$e->getMessage()."\n"; | ||
} | ||
?> | ||
--EXPECTF-- | ||
Exception: Offset invalid or out of range |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--TEST-- | ||
SPL: DoublyLinkedList: insert operations | ||
--FILE-- | ||
<?php | ||
$dll = new SplDoublyLinkedList(); | ||
// errors | ||
try { | ||
$dll->add(2,5); | ||
} catch (OutOfRangeException $e) { | ||
echo "Exception: ".$e->getMessage()."\n"; | ||
} | ||
|
||
$dll->add(0,6); // 6 | ||
$dll->add(0,3); // 3 6 | ||
// Insert in the middle of the DLL | ||
$dll->add(1,4); // 3 4 6 | ||
$dll->add(2,5); // 3 4 5 6 | ||
$dll->unshift(2); // 2 3 5 4 6 | ||
// Insert at the beginning and end of the DLL | ||
$dll->add(0,1); // 1 2 3 4 5 6 | ||
$dll->add(6,7); // 1 2 3 4 5 6 7 | ||
|
||
echo count($dll)."\n"; | ||
|
||
echo $dll->pop()."\n"; | ||
echo $dll->pop()."\n"; | ||
echo $dll->pop()."\n"; | ||
echo $dll->pop()."\n"; | ||
echo $dll->pop()."\n"; | ||
echo $dll->pop()."\n"; | ||
echo $dll->pop()."\n"; | ||
?> | ||
===DONE=== | ||
<?php exit(0); ?> | ||
--EXPECTF-- | ||
Exception: Offset invalid or out of range | ||
7 | ||
7 | ||
6 | ||
5 | ||
4 | ||
3 | ||
2 | ||
1 | ||
===DONE=== |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this have an (int) cast? index is declared as long, so the types should match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly for the same reason that I wasn't certain why offsetUnset() also casts to int, while other methods like offsetExists() and offsetGet() don't: I wasn't sure if I was missing something elsewhere in the code, and preferred to err on the side of caution.... or is offsetUnset() also wrong in this cast?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems wrong to me, I will fix offsetunset.
EDIT: Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, I'll happily change add() and push again