note 2885 deleted from Session handling functions by sniper

From: Date: Mon, 02 Jul 2001 08:14:57 +0000
Subject: note 2885 deleted from Session handling functions by sniper
Groups: php.notes 
Request: Send a blank email to php-notes+get-14863@lists.php.net to get a copy of this message
I have worked through a problem trying to use an array as a session variable. I thought I'd post the problem and resolution here to help someone through the trials I just went through :-) The problem was: I was getting a PHP Warning "Variable passed to each() is not an array or object in my.inc on line 52". I was doing the following test: if(!isset(my_array)) { my_array = filler_up(); } apparently, PHP somehow set it to blank through session_register("my_array") because isset(my_array) was coming back true but then when I tried each($my_array) it failed. I haven't had an opportunity to set $my_array for the first time! So, what I did was change my test to this: if(!isset($my_array) || !is_array($my_array)) { $my_array = filler_up(); } Apparently (from the is_array() comments) is_array() also sets the variable to type "array" in addition to checking (I'm not sure that's a good idea ...) But the second test fails if $my_array hasn't been set yet, and then all works fine (session variables and everything) now. Happy Coding<P> Jeffrey Thompson<BR> jeffrey@thompsonic.com<BR> http://www.thompsonic.com<BR>

« previous php.notes (#14863) next »