php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18307 Using next () && prev() on session array
Submitted: 2002-07-12 07:57 UTC Modified: 2002-07-14 07:50 UTC
From: submiturl at vaner dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.1 OS: WinXP
Private report: No CVE-ID: None
 [2002-07-12 07:57 UTC] submiturl at vaner dot com
I've tried to use next() and prev() on a array that was registerd with session. unfortunatelly it did not produce desired outcome.


instead of traversing array fully it doesnt proceed after a second element. 
and when prev() is used the internal pointer gets stuffed so seach returns false.


----------------CODE---------

<?
	session_start();
	if(!session_is_registered('session_array')){
		session_register('session_array');
		$session_array = Array();
		$session_array []=count($session_array);
		$session_array []=count($session_array);
		$session_array []=count($session_array);
		$session_array []=count($session_array);
		$session_array []=count($session_array);
		$session_array []=count($session_array);
		$session_array []=count($session_array);
		$session_array []=count($session_array);
		$session_array []=count($session_array);
		$session_array []=count($session_array);
		print_r($session_array);
	}


	if(isset($programAction) && $programAction == "Next"){
		next($session_array);
	}
	if(isset($programAction) && $programAction == "Prev"){
		prev($session_array);
	}

	echo current($session_array);
?>

<form name="form1" method="get" action="<?=$_SERVER['PHP_SELF']?>">
  <input name="programAction" type="submit" id="programAction" value="Prev">
  <input name="programAction" type="submit" id="programAction" value="Next">
</form>

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-12 08:08 UTC] submiturl at vaner dot com
i was using PHP 4.1.2
 [2002-07-12 08:10 UTC] derick@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
 [2002-07-12 21:22 UTC] submiturl at vaner dot com
The same thing happends on 4.2.1 version

--- UPDATED CODE ---

<?
session_start();
if(!isset($_SESSION['array'])){

$_SESSION['array'] = Array();
$_SESSION['array'] []=count($_SESSION['array']);
$_SESSION['array'] []=count($_SESSION['array']);
$_SESSION['array'] []=count($_SESSION['array']);
$_SESSION['array'] []=count($_SESSION['array']);
$_SESSION['array'] []=count($_SESSION['array']);
$_SESSION['array'] []=count($_SESSION['array']);
$_SESSION['array'] []=count($_SESSION['array']);
$_SESSION['array'] []=count($_SESSION['array']);
$_SESSION['array'] []=count($_SESSION['array']);
$_SESSION['array'] []=count($_SESSION['array']);
print_r($_SESSION['array']);
}


if(isset($_REQUEST['programAction']) && $_REQUEST['programAction'] == "Next"){
	next($_SESSION['array']);
}
if(isset($_REQUEST['programAction']) && $_REQUEST['programAction'] == "Prev"){
	prev($_SESSION['array']);
}

echo current($_SESSION['array']);
?>

<form name="form1" method="get" action="<?=$_SERVER['PHP_SELF']?>">
  <input name="programAction" type="submit" id="programAction"
value="Prev">
  <input name="programAction" type="submit" id="programAction"
value="Next">
</form>
 [2002-07-12 21:41 UTC] sniper@php.net
Why do you expect that to work?
You don't store the current index anywhere, so
it it's always starting from the first item..


 [2002-07-13 23:39 UTC] submiturl at vaner dot com
from the manual : "The session support allows you to register arbitrary numbers of variables to be preserved across requests"
Preserved means that the internal pointer of the array should be preserved to .. right???
i have posted this http://bugs.php.net/?id=18309 ( serialize of array doesn not preserve internal pointer) but its been calsified as bogus.

Becasue Next() works on the array no defiend as a session array... it should work in the same manner on the session array.
 [2002-07-14 07:50 UTC] derick@php.net
Array pointers are not stored when saving an array. This is not a bug -> bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC