Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

SplObjectStorage #327

Closed
wants to merge 5 commits into
from
Commits on Apr 24, 2011
  1. Fix SplObjectStorage implementation.

    udat committed Apr 24, 2011
    Test case:
      <?php
    
        $storage = new SplObjectStorage();
        $objects = array();
    
        for ($i=0; $i<5; ++$i) {
          $objects[] = new StdClass;
        }
        for ($i=0; $i<5; ++$i) {
          $storage->attach($objects[$i]);
        }
    
        $storage->next();
    
        for ($i=0; $i<4; ++$i) {
          $storage->detach($objects[$i]);
        }
    
        echo $storage->key();
        ?>
    
    PHP result:
        0
    
    HPHP result (before patch):
        HipHop Notice:  In PHP, mixing up foreach() and functional style array iteration by calling current(), each(), key(), value(), prev(), next() may lead to undefined behavior. In HipHop, this problem is
        less severe, but to avoid inconsistency between PHP and HipHop, please call reset() or end() after foreach and before calling any of those array iteration functions.
        HipHop Warning:  Not a valid stream resource
        HipHop Warning:  Not a valid stream resource
        HipHop Warning:  Not a valid stream resource
        HipHop Warning:  Not a valid stream resource
        1
    
    HPHP result (after patch):
        HipHop Notice:  In PHP, mixing up foreach() and functional style array iteration by calling current(), each(), key(), value(), prev(), next() may lead to undefined behavior. In HipHop, this problem is
        less severe, but to avoid inconsistency between PHP and HipHop, please call reset() or end() after foreach and before calling any of those array iteration functions.
        1
Commits on Apr 25, 2011
  1. Implement addAll, removeAll, removeAllExcept, offsetGet, offsetExists…

    udat committed Apr 25, 2011
    …, offsetSet, offsetUnset methods of SplObjectStorage class.
    
    Test case:
    
      <?php
        namespace test;
    
        class D extends \SplObjectStorage {
          public function clear() {
           $this->removeAll($this);
          }
        }
    
        $o1 = new \StdClass;
        $o2 = new \StdClass;
        $a = new D();
    
        $a[$o1] = "foo";
        var_dump(count($a));
    
        $a->clear();
        var_dump(count($a));
    
        $a[$o1] = "foo";
    
        $b = new D();
        $b[$o1] = "bar";
        $b[$o2] = "gee";
    
        var_dump(count($b));
        $b->removeAll($a);
        var_dump(count($b));
    
        var_dump($b[$o2]);
        $b->removeAllExcept($a);
        var_dump(count($b));
Commits on May 1, 2011
  1. Fix four bugs in SplObjectStorage and regenerate system.

    udat committed May 1, 2011
    1. SplObjectStorage::valid() - behaviour difference
    
      In PHP after call to SplObjectStorage::next(), which advance internal pointer after array last element, any subsequent call to SplObjectStorage::valid() should return false, even if
    SplObjectStorage::attach was called. Also SplObjectStorage::valid() returns false until SplObjectStorage::rewind() is called on non-empty storage.
    
      For example:
       <?php
          $s = new SplObjectStorage();
          $s->rewind();
          $s->attach(new StdClass());
          var_dump($s->valid()); //should return false
          $s->rewind();
          var_dump($s->valid()); //should return true
          $s->next();
          var_dump($s->valid()); //should return false
          $s->attach(new StdClass());
          var_dump($s->valid()); //should return false
    
    2. SplObjectStorage->index property wasn't reset to 0 after SplObjectStorage::rewind() is called
    3. Call to SplObjectStorage::setInfo() added new element to $storage array if iterator wasn't pointing to valid object.
    4. SplObjectStorage->valid method was comparing `current($this->storage)` return value to false instead of null.