php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12859 Session unable to store array of classes
Submitted: 2001-08-20 08:31 UTC Modified: 2002-01-09 02:04 UTC
From: philipmateescu at hotmail dot com Assigned:
Status: Closed Package: Session related
PHP Version: 4.0.6 OS: W2k, Linux
Private report: No CVE-ID: None
 [2001-08-20 08:31 UTC] philipmateescu at hotmail dot com
Session is unable to store an array of classes. If you try to add to an array (using []) stored in the session, it overrides the array instead of adding to it

Here's a sample code:


<?
include_once("cls1.php");
if (!session_is_registered("ClassOne")) {
	session_register("ClassOne");
	echo "<BR>ClassOne now in session";
}
?>
<BR><B>Right now we have <?= sizeof($HTTP_SESSION_VARS["ClassOne"])?> classes</B>.<P>
<?
if ($HTTP_GET_VARS["count"] != 0) {
	for ($i = 0; $i < $HTTP_GET_VARS["count"]; $i++) {
		$HTTP_SESSION_VARS["ClassOne"][] = new ClassOne(); //this line should add to the array
	}	
}

?>
<B>And now we have <?= sizeof($HTTP_SESSION_VARS["ClassOne"])?> classes</B>.<P>

<form method="get" action="regcls.php">
Register <input type="text" name="count" size="3"> objects.
<input type="submit">
</form>
<PRE>
<?
if ($HTTP_GET_VARS["delete"] == 1) {
	
	echo "<BR>Killing CountOne from session...";

	$HTTP_SESSION_VARS["CountOne"]=0;
	session_unregister("CountOne");

}
for ($i=0; $i < sizeof($HTTP_SESSION_VARS["ClassOne"]); $i++) {
	echo "\n$i ClassOne->count = ". $HTTP_SESSION_VARS["ClassOne"][$i]->getCount();
}
?>
</PRE>
<?
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-12-19 22:15 UTC] yohgaki@php.net
Please test with 4.1.0 and latest CVS snapshot.
CVS snapshot can be found 
http://snaps.php.net/

If you don't have problem with latest CVS snapshot,
you can close your bug report by yourself.

Please report the result. When you update your bug
report, do not forget updating PHP version also.

Thank you
-- 
Yasuo
 [2002-01-09 02:04 UTC] lobbin@php.net
No feedback. Closing.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 05 22:01:30 2025 UTC