Skip to content

Instantly share code, notes, and snippets.

@sun
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save sun/180f508862b30b6cb973 to your computer and use it in GitHub Desktop.

Select an option

Save sun/180f508862b30b6cb973 to your computer and use it in GitHub Desktop.

Revisions

  1. sun revised this gist Jul 30, 2014. 2 changed files with 18 additions and 0 deletions.
    1 change: 1 addition & 0 deletions bug.php
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@
    }
    }

    // Also note that 'two' gets re-keyed to 0 (but that seems to be expected behavior).
    $expected = array('two');

    echo "-- Actual result:\n", var_dump($list), "\n";
    17 changes: 17 additions & 0 deletions result
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    $ php bug.php
    -- Actual result:
    class SplDoublyLinkedList#1 (2) {
    private $flags =>
    int(2)
    private $dllist =>
    array(1) {
    [0] =>
    string(3) "one"
    }
    }

    -- Expected result:
    array(1) {
    [0] =>
    string(3) "two"
    }
  2. sun created this gist Jul 30, 2014.
    19 changes: 19 additions & 0 deletions bug.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    <?php

    $list = new SplDoublyLinkedList();
    // Comment this out to make it behave.
    $list->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO);

    $list->push('one');
    $list->push('two');

    foreach ($list as $key => $value) {
    if ($value === 'one') {
    unset($list[$key]);
    }
    }

    $expected = array('two');

    echo "-- Actual result:\n", var_dump($list), "\n";
    echo "-- Expected result:\n", var_dump($expected), "\n";