$arrDateObjects[] = $objDateStartMin->addDay( 1 ); will just create a
reference to that object instead of a new one.
To get a copy of the object use the "clone" constructor:
$arrDateObjects[] = clone $objDateStartMin->addDay( 1 );
Juan Felipe Alvarez Saldarriaga wrote:
>
> Bug in Zend_Date? When I try to store Zend_Date objects into an array,
> using a while to create a range of dates, when I print the array is the
> same last object per array element, but why ? the array keys are
> consecutives, I try with a counter as key and doesn't work either, finally
> I fix it creating a new object per iteration, but I don't know if
> something is wrong with my code, this what I'm doing:
>
> $objDateStartMin = new Zend_Date( "2008-08-12 00:00:00" );
>
> $objDateEndMax = new Zend_Date( "2008-09-26 00:00:00" );
>
> $arrDateObjects = array();
>
> while ( $objDateEndMax->isLater( $objDateStartMin ) )
> {
> // When I store the object in the array in the final array just appear
> the last iteration for all array elements.
> $arrDateObjects[] = $objDateStartMin->addDay( 1 );
>
> // Ugly fix.
> // $arrDateObjects[] = new Zend_Date( $objDateStartMin->addDay( 1 ) );
> }
>
> // When I print the array of object is the same last object of the
> iteration, look the timestamp, same for all array elements.
>
> ...
>
--
View this message in context:
http://www.nabble.com/Bug-in-Zend_Date--or-I%27m-doing-something-wrong--tp19100534p19100946.html
Sent from the Zend Framework mailing list archive at Nabble.com.