Re: Sessions auto storing class
- From: Jerry Stuckle <jstucklex@xxxxxxxxxxxxx>
- Date: Wed, 27 May 2009 06:31:04 -0400
UKuser wrote:
Hi Folks,
I'm working on a basket at the moment, however I'm experiencing
something VERY wierd. My local scripts work fine, however my live ones
error saying I'm trying to use an object as an array. What I
discovered is that $_SESSION is outputting:
Array
(
[basket] => basket_orders Object
(
[site] => site Object
(
[db] => Zend_Db_Adapter_Mysqli Object
(
[_numericDataTypes:protected] => Array
(
So evidently, SESSION is storing my object but it should only be
storing the data I provide to it?? My Constructor for "basket_orders"
is:
public function __construct($get,$post){
session_start();
require_once("class_site.php");
$site = new site;
$this->site = $site;
switch ($get['act']){
case "add": return $this->addBasket($post); break;
case "del": return $this->deleteBasket($post); break;
case "upd": return $this->updateBasket($post); break;
case "count": return $this->countBasket(); break;
case "show":
if (isset($get['test'])){
print"<pre>";print_r($_SESSION);print"</pre>";exit;
}
return $this->showBasket($get); break; // used for the main
basket page
case "drop": return $this->dropBasket(); break;
// Again - added for testing purposes
case "clear":
session_start();
$_SESSION = array();
$_COOKIE = array();
session_destroy();
header("location:products.php?pid=1");
break;
}
}
I don't believe I'm doing anything blindingly stupid, but am happy to
be advised otherwise.
I hope that sounds familiar - I don't want to paste my whole script in
here as its a few hundred lines, but let me know if you need anything
more.
Thanks
A
This is a constructor, but what class is this in?
I don't see anywhere you are storing data in the $_SESSION array or retrieving from that array, other than clearing it with $_SESSION=array() (which, BTW, is not a good idea - it's better to unset() the appropriate values).
If you are storing the object in the $_SESSION array, then you must include the class definition before you call session_start().
One other thing - generally it's not a good idea to call session_start() within a function. Things have a tendency to go bad if you either call session_start() more than once or output anything before the call to session_start(). I find it better to just place it at the top of each page (after any required include files, of course).
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================
.
- Follow-Ups:
- Re: Sessions auto storing class
- From: UKuser
- Re: Sessions auto storing class
- References:
- Sessions auto storing class
- From: UKuser
- Sessions auto storing class
- Prev by Date: Sessions auto storing class
- Next by Date: Re: Sessions auto storing class
- Previous by thread: Sessions auto storing class
- Next by thread: Re: Sessions auto storing class
- Index(es):
Relevant Pages
|