ID:               47623
 Updated by:       j...@php.net
-Summary:          array_shift() with SESSION
 Reported By:      Henry at huis-stijl dot nl
-Status:           Open
+Status:           Verified
 Bug Type:         Scripting Engine problem
 Operating System: Apache/2.0.52 (CentOS)
 PHP Version:      5.2.9
 New Comment:

This has nothing to do with sessions. Simplified script:

<?php

$foo['villas'] = array('a','b','c');

while($foo['villas'] != array())
{
  $row = array_shift(@$foo['villas']); // Removing @ makes it work..
  var_dump($foo);
}
?>




Previous Comments:
------------------------------------------------------------------------

[2009-03-16 22:11:28] Henry at huis-stijl dot nl

Tried with and without the @ same output.

------------------------------------------------------------------------

[2009-03-16 16:26:07] j...@php.net

If you remove those @'s, what does it output..?

------------------------------------------------------------------------

[2009-03-11 14:07:22] Henry at huis-stijl dot nl

<?php
        session_start();
        ini_set('session.cache_limiter', 'private');
// © 2009 Huis-stijl, Henry Hekman

        $_SESSION['villas'] = array
                (
                        1 => array(1,2,3),
                        2 => array(2,3,4),
                        3 => array(3,4,5),
                        4 => array(4,5,6),
                );

        While(@$_SESSION['villas'] != array())
                {
                        $row = array_shift(@$_SESSION['villas']);
                        print_r($row);
                }// einde while

?>

on php 4 i get
Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 2 [1] => 3 [2] => 4
) Array ( [0] => 3 [1] => 4 [2] => 5 ) Array ( [0] => 4 [1] => 5 [2] =>
6 )

on phph 5.2.9 i get a loop that doesnt end
Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 3
) Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] =>
3 ) Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2]
=> 3 ) Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2
[2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] =>
2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1]
=> 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 3 )

------------------------------------------------------------------------

[2009-03-11 12:56:34] Henry at huis-stijl dot nl

Description:
------------
Script was working perfectly on PHP 4 when updated to PHP5.2.9 I found
an error. I was filling a array in the session and looped it with
array_shift until the arry was empty. 
This loop kept giving me the first value but did not erased it from te
original arry.

Reproduce code:
---------------
$row = array_shift(@$_SESSION['villas']);

Expected result:
----------------
1. $row getting the first element from $_SESSION['villas']
2. $_SESSION['villas'] to get lost the first element.


Actual result:
--------------
1. $row getting the first element from $_SESSION['villas']
2. $_SESSION['villas'] did not lost the first element and was
unchanged


I cann bypass this failure by using:
$arr_temp = @$_SESSION['villas'];
$row = array_shift($arr_temp);
$_SESSION['villas'] = $arr_temp;
unset($arr_temp);




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47623&edit=1

Reply via email to