#27586 [Opn->Asn]: ArrayObject::getIterator crashes with [] assignment

From: Date: Sat, 13 Mar 2004 19:50:38 +0000
Subject: #27586 [Opn->Asn]: ArrayObject::getIterator crashes with [] assignment
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-56403@lists.php.net to get a copy of this message
ID: 27586 Updated by: helly@php.net -Summary: ArrayObject::getIterator crashes Apache 2 Reported By: ebay at webcrumb dot com -Status: Open +Status: Assigned -Bug Type: Arrays related +Bug Type: Class/Object related -Operating System: Windows XP +Operating System: * PHP Version: 5.0.0b4 (beta4) -Assigned To: +Assigned To: helly Previous Comments: ------------------------------------------------------------------------ [2004-03-13 11:35:38] ebay at webcrumb dot com 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', 'j.blo@here.com' ) ); $students->add( new Student( '00000014', 'Bob', 'Moe', 'b.moe@qut.edu.au' ) ); 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 this bug report at http://bugs.php.net/?id=27586&edit=1

« previous php.bugs (#56403) next »