SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Refactoring = reboot ... help please!

    Hi,

    Im refactoring my collection class, which makes use of the IteratorAggragate object in the SPL.

    Anyway, you have to provide your class with an getIterator method which calls upon an..... heel yeah.. iterator

    Well you all know programming to interfaces is one of the design rules and im trying to calculate this in my refactoring phase.

    What i mean is this is how i get my Iterator object now :

    public function getIterator(){
    return(new Iterator(clone($this))); //You want a deep copy trust me
    }

    which im trying to refactor to something like :

    public function getIterator(){
    $iteratorObject = factory::createDataObject(7); // 7 = datatype
    $iteratorObject->assignCollection(clone($this));
    $iteratorObject->initialize(); //currIndex = 0, keys = collectionkeys etc..
    }

    but when i try to run this code instead of the previous i get appache to completely break down with and the server needs a reboot.

    Now somehow i suspect the IteratorAggregate to be responsible for this problem, also the fact that this is a copy rather then a reference is maybe the problem, but that would mean i can not refactor this piece which does my head in.

    if anyone has any clues on how to solve this please go ahead and explain
    thanks a milion,
    Galo
    Business as usual is off the menu folks, ...

  2. #2
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you returning anything from your getIterator() method? Could be tripping a PHP bug.

    Douglas
    Hello World

  3. #3
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DougBTX
    Are you returning anything from your getIterator() method? Could be tripping a PHP bug.

    Douglas

    im sorry doug
    PHP Code:
    public function getIterator(){
    $this->_checkCallback();
    $iterator Factory::createData('7');
    $iterator->assign(clone($this));
    return(
    $iterator);

    should do exacly the same as my previous call only in a few more steps, but the getIterator method is called automaticly whenever using foreach on your collections.

    PHP Code:
    foreach($myCollection as $collectionElement){
        
    //Foo, now the getIterator method get's invoked through the IteratorAggregate interface

    Im still not able to do it this way, this must be a method reference then no ?

    cheers,
    Galo
    Business as usual is off the menu folks, ...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •