[PHP] SESSION var and Objects problem
My first foray into classes objects. When retrieving a set of records, I'm using a class to build an object. At this time I save each record/object into a Session array by doing this: $rows = mysql_num_rows($qrslts); if ($rows 0) for ($i=1;$i=$rows;$i++) { $row = mysql_fetch_array($qrslts); $e = new Entry; if ($e-GetAnEntry($row['recordkey'],$row['Eventcode'])) { $evts[] = $e; array_push($_SESSION['TMScurr_evts'],$e); // THIS DOESN'T $cls_errs .= Stored $e-event in sess var $i-1; ; // THIS WORKS } else $cls_errs .= Could not retrieve event record for .$row['recordkey']. .$row['Eventcode']; } The above code works AFAIK - the line above the array_push correctly stores my retreived record data in the $evts array just fine and I can see the data when I use that array to display my page. Note also that the var $cls_errs following the array_push does show me that valid values are being stored in $e Later on, in my main process I attempt to retreive the contents of my Session var to use to re-display the data. The code for that doesn't display any values. In trying to debug this here is what I've done: $cnt = count($_SESSION['TMScurr_evts']); echo In Display process with $cnt recs in session var TMScurr_evts. ; // THIS WORKS reset($_SESSION['TMScurr_evts']); $e = new Entry; for ($i=0;$icount($_SESSION['TMScurr_evts']);$i++) { $e = array_pop($_SESSION['TMScurr_evts']); echo in Display process - sess event $i is $e-eventbr;// THIS DOESN'T } This debugging code correctly tells me how many entries are in the Session array variable, but the attempt to echo the values stored in the first field of each object contained in it shows blank for each one. What am I doing wrong when I try to pull the contents of my session array out and store them back into an Entry object, one at a time, so that I can display the object on my webpage?? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SESSION var and Objects problem
On 2 Mar 2012, at 20:07, Jim Giner wrote: My first foray into classes objects. When retrieving a set of records, I'm using a class to build an object. At this time I save each record/object into a Session array by doing this: $rows = mysql_num_rows($qrslts); if ($rows 0) for ($i=1;$i=$rows;$i++) { $row = mysql_fetch_array($qrslts); $e = new Entry; if ($e-GetAnEntry($row['recordkey'],$row['Eventcode'])) { $evts[] = $e; array_push($_SESSION['TMScurr_evts'],$e); // THIS DOESN'T $cls_errs .= Stored $e-event in sess var $i-1; ; // THIS WORKS } else $cls_errs .= Could not retrieve event record for .$row['recordkey']. .$row['Eventcode']; } What is the type of $e (i.e. what's the class called)? Side note... it looks like GetAnEntry fetches the entry into internal data. This isn't really how objects are supposed to work. To be more OO-like you should be passing the recordkey and Eventcode values into the constructor. But that's not relevant to your issue. The above code works AFAIK - the line above the array_push correctly stores my retreived record data in the $evts array just fine and I can see the data when I use that array to display my page. Note also that the var $cls_errs following the array_push does show me that valid values are being stored in $e Later on, in my main process I attempt to retreive the contents of my Session var to use to re-display the data. The code for that doesn't display any values. In trying to debug this here is what I've done: $cnt = count($_SESSION['TMScurr_evts']); echo In Display process with $cnt recs in session var TMScurr_evts. ; // THIS WORKS reset($_SESSION['TMScurr_evts']); $e = new Entry; for ($i=0;$icount($_SESSION['TMScurr_evts']);$i++) { $e = array_pop($_SESSION['TMScurr_evts']); echo in Display process - sess event $i is $e-eventbr;// THIS DOESN'T } This debugging code correctly tells me how many entries are in the Session array variable, but the attempt to echo the values stored in the first field of each object contained in it shows blank for each one. What am I doing wrong when I try to pull the contents of my session array out and store them back into an Entry object, one at a time, so that I can display the object on my webpage?? In the above script, the one that gets the objects out of the session, has the class been declared? IOW, have you included the PHP file that defines that class? If not then it won't be able to recreate the object. If that was the problem then I suggest you make sure you have error_reporting set to at least E_ALL, and display_errors set on, because this issue will be causing a fatal error, the text of which would make it obvious what's going wrong. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SESSION var and Objects problem
Yes I ahve the class defined. The classes work in most cases - just this one place where I want to save the objects in a sess var for re-use fails me. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SESSION var and Objects problem
Please quote the pertinent bit of the message you're replying to, it makes using the list a halluvalot easier and improves SEO for the archives. On 2 Mar 2012, at 20:55, Jim Giner wrote: Yes I ahve the class defined. The classes work in most cases - just this one place where I want to save the objects in a sess var for re-use fails me. Put the following line at the top of the code that you posted and post the output. echo 'pre'; var_dump($_SESSION['TMScurr_evts']); die('/pre'); Have you checked your error log, or your error settings? Scripts generally don't stop executing for no reason or without saying why. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SESSION var and Objects problem
ok - In examinig the objects in the Session after the data has been displayed and the user has hit triggered a re-entry into my script (just one script involved here), the objects in the session array now say [__PHP_Incomplete_Class_Name and __PHP_Incomplete_Class Object . They didn't say that during my examiniation of the sess var before exiting the script. Also with All error reporting on (a great tip that I never think of) I get many messages indicating that the object may not have been loaded. I don't know what this means. The include file for my class is present in my script and is always loaded. But at this point in the process no functions of the class have been called. Is that a problem? In trying to re-display my data stored in the Sessioin array I instantiate a var of the class and then pop an array off the session var and assign it to the object and then call my display function to show the data on the webpage - that is where I get the errors. Here is one of these messages: Notice: DisplayAnEntry() [function.displayanentry]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition Entry of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /home/albany/public_html/tms/php/tmsentry.php on line 372 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SESSION var and Objects problem
On 2 Mar 2012, at 21:09, Jim Giner wrote: ok - In examinig the objects in the Session after the data has been displayed and the user has hit triggered a re-entry into my script (just one script involved here), the objects in the session array now say [__PHP_Incomplete_Class_Name and __PHP_Incomplete_Class Object . They didn't say that during my examiniation of the sess var before exiting the script. Also with All error reporting on (a great tip that I never think of) I get many messages indicating that the object may not have been loaded. I don't know what this means. The include file for my class is present in my script and is always loaded. But at this point in the process no functions of the class have been called. Is that a problem? In trying to re-display my data stored in the Sessioin array I instantiate a var of the class and then pop an array off the session var and assign it to the object and then call my display function to show the data on the webpage - that is where I get the errors. Here is one of these messages: Notice: DisplayAnEntry() [function.displayanentry]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition Entry of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /home/albany/public_html/tms/php/tmsentry.php on line 372 Make sure the class is declared before you call session_start. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SESSION var and Objects problem
Stuart Dallas stu...@3ft9.com wrote in message news:7eeba658-c7f6-4449-87bd-aac71b41e...@3ft9.com... Make sure the class is declared before you call session_start. * You Da Man!! I see now why it makes a difference. The session tries to bring back the data but doesn't know how to handle the objects in the session vars since the objects haven't been defined. Never would of thought of that! Thank you for being there! :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] SESSION var and Objects problem
Hi, Jim To avoid this kind of problem it would also help to provide an autoloader-function as PHP then tries to load the class-definition by this autoloader ;) Using that you'd bind yourself to have a pretty good system for php-classes and you'd avoid having problems like that. I'd in fact have never thought about a solution like that - but that may comes from the fact that I always use auto-loader-scripts ;) One additional info: I had some problems putting an instance of *SimpleXmlElement *into the session ... The only valuable info I found was this error: *Fatal error: Exception thrown without a stack frame in Unknown on line 0* Here's the solution and description why: http://stackoverflow.com/questions/4624223/object-in-session-fatal-error-exception-thrown-without-a-stack-frame-in-unknow#answer-4624256 Bye Simon 2012/3/2 Jim Giner jim.gi...@albanyhandball.com Stuart Dallas stu...@3ft9.com wrote in message news:7eeba658-c7f6-4449-87bd-aac71b41e...@3ft9.com... Make sure the class is declared before you call session_start. * You Da Man!! I see now why it makes a difference. The session tries to bring back the data but doesn't know how to handle the objects in the session vars since the objects haven't been defined. Never would of thought of that! Thank you for being there! :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php