From:             ebay at webcrumb dot com
Operating system: Windows XP
PHP version:      5.0.0b4 (beta4)
PHP Bug Type:     Arrays related
Bug description:  ArrayObject::getIterator crashes Apache 2

Description:
------------
I'm not sure if I'm using ArrayObject correctly (I thought you could use
the primitive type 'array' directly to fetch iterators initially but it
seems that's not the case), but I can't tell due to the lack of
documentation ...



All latest service packs/patches are installed.





Reproduce code:
---------------
class StudentList implements IteratorAggregate

{

        private $students;

        

        public function __construct() {

                $this->students = new ArrayObject( array() );

        }

        

        public function add( Student $student ) {

                if( !$this->contains( $student ) ) {

                        // XXXX: this causes the crash!

                        $this->students[] = $student;

                }

        }



        // ... snip ...



        public function getIterator() {

                return $this->students->getIterator();

        }

}



$students = new StudentList();

$students->add( new Student( '01234123', 'Joe', 'Blo', '[EMAIL PROTECTED]' )
);

$students->add( new Student( '00000014', 'Bob', 'Moe', '[EMAIL PROTECTED]'
) );



foreach( $students as $student ) {

        echo $student->getId(); // first parameter passed to the above
constructors

}



Expected result:
----------------
This should print out "0123412300000014".

Actual result:
--------------
The Apache 2 service crashes hard.



Resolved by:



public function __construct() {

  $this->students = array();

}



// ... snip ...



public function getIterator() {

  $arr = new ArrayObject( $this->students );

  return $arr->getIterator();

}



Using this code, the expected result is printed out.



-- 
Edit bug report at http://bugs.php.net/?id=27586&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27586&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27586&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27586&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27586&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27586&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27586&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27586&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27586&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27586&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27586&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27586&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27586&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27586&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27586&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27586&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27586&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27586&r=float

Reply via email to