php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24202 problem with array of objects stored in session vars
Submitted: 2003-06-16 05:51 UTC Modified: 2003-06-16 10:33 UTC
From: admin at nexusfor dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 4.3.2 OS: WIN NT
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: admin at nexusfor dot com
New email:
PHP Version: OS:

 

 [2003-06-16 05:51 UTC] admin at nexusfor dot com
Description:
------------
When I read an array of objects saved in a session variable I cannot access object's variables.

Print_r reports:

Array ( [0] => __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] => class_voucher_dettaglio [descrizione] => A3 [gg] => 1 [periodi] => 1 [base] => 23 [totale] => 23 )

This problem appears only when php retrieves variable from session_file (that appear correct)

Reproduce code:
---------------
while (list ($key, $val ) = each ($_SESSION ["PREV_DETTAGLIO"] ) )
    {
	 echo ($val->dettaglio); 
    }



Expected result:
----------------
list of values

Actual result:
--------------
nothing

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-16 08:27 UTC] sniper@php.net
You're doing something wrong. (not enough info to be sure, but it works just fine here when you do it right..)

 [2003-06-16 08:51 UTC] admin at nexusfor dot com
I'm sure that there's something wrong.

this script shows the problem in 4.3.1/4.3.2 release for WIN

<?
class bogus
{
 var $a;
} 

$b = new bogus;
$b -> a = $HTTP_GET_VARS["b"]; 
    
$_SESSION ["SESS"] = array_merge ($_SESSION ["SESS"], array ($b) );

print_r ($_SESSION ["SESS"]);
reset ($_SESSION ["SESS"] );

$i = 0;
while (list ($key, $val ) = each ($_SESSION ["SESS"] ) )
 {
   echo $val->a;
 }	
?> 

the scalar version just work file

<?

$b = $HTTP_GET_VARS["b"]; 
    
$_SESSION ["SESS"] = array_merge ($_SESSION ["SESS"], array ($b) );

print_r ($_SESSION ["SESS"]);
reset ($_SESSION ["SESS"] );

$i = 0;
while (list ($key, $val ) = each ($_SESSION ["SESS"] ) )
 {
   echo $b;
 }	
?> 

thank you
 [2003-06-16 09:40 UTC] admin at nexusfor dot com
second source correction:

<?

$b = $HTTP_GET_VARS["b"]; 
    
$_SESSION ["SESS"] = array_merge ($_SESSION ["SESS"], array ($b) );

print_r ($_SESSION ["SESS"]);
reset ($_SESSION ["SESS"] );

$i = 0;
while (list ($key, $val ) = each ($_SESSION ["SESS"] ) )
 {
   echo $val;
 }	
?> 

sorry for the mistake
 [2003-06-16 09:55 UTC] derick@php.net
doh! You forgot session_start() everywhere...
 [2003-06-16 10:14 UTC] admin at nexusfor dot com
I'm lazy man so I set session.auto_start = 1 in my php.ini :-)

I also tried with explicit session_start(), the problem persists.

session serialiazation seems to works fine 
here the tmp file:

SESS|a:2:{i:0;O:5:"bogus":1:{s:1:"a";s:1:"1";}i:1;O:5:"bogus":1:{s:1:"a";s:1:"1";}}

Today is just an horrible monday for me, but I'm sure that there is something strange and I don't think that problem is in the script.

the code works fine in your environment ?
 [2003-06-16 10:25 UTC] sniper@php.net
From the Friendly Manual:

"If you do turn on session.auto_start then you cannot put 
objects into your sessions since the class definition has to 
be loaded before starting the session in order to recreate
the objects in your session."

 [2003-06-16 10:31 UTC] admin at nexusfor dot com
thank you for the suggestion.
 [2003-06-16 10:33 UTC] sniper@php.net
It's not a suggestion, it's requirement. 
session.auto_start has to be OFF if you want to store
objects in sessions.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 23:01:26 2024 UTC