Any idea why serialize/unserialize works fine on my local installation (Win98SE, PHP 4.1.2), but drives me crazy under Unix (PHP 4.2.2) at a free internet account?
There I always get a "Fatal error: Call to a member function on a non-object" error.
My frustration level is running high, so any help is truly appreciated, thx alk what is the cod eyou are using? I never had a problem with serialize on a unix box.I have a class called skim (for skim through ...) that has the following member function (just an excerpt):
function showNavigation($dest_page, $link_style, $session_id) {
$skim_serialized = serialize($this);
...
if (0 != $this->m_curPage) {
echo "<A class='$link_style' HREF='http://www.htmlforums.com/archive/index.php/$dest_page?curPage=" .($this->m_curPage-1);
echo "&skim=$skim_serialized$session_id'>";
echo "Previous </A>\n";
}
...
}
all this is in an file called skim.inc.php
Now the file where I use the stuff:
<?php
include("connect.inc.php");
include("../skim.inc.php");
$SID = connect_to_mysite();
session_register("sesUserID", "sesUserName", "sesUserRights");
if (!isset($sesUserID)) header("Location: connect.php?doAuth=1");
if(SID) {
$sid1 = "?" . SID;
$sid2 = "&" . SID;
}
// check if information to skim through the result pages has been sent
if(isset($skim)) { $skimObj = unserialize($skim); }
else { $skimObj = new skim(20); }
// set the number of the current page
if (isset($curPage)) { $skimObj->setCurrentPage($curPage); }
...
The error comes when setCurrentPage() is called. I tried using urlencode/urldecode and base64_encode/base64_decode on the serialized string, but that didn't help. where is the function setCurrentPage()The function is part of the skim class like showNavigation(). Actually it does not to much - see for yourself:
function setCurrentPage($curPage) { $this->m_curPage = $curPage; }
The problem is that the object (skimObj) is not correctly created when calling unserialize (I guess).well from my understanding of classes is that anytime you have $var->something) it usually menas you are working in a class. but seeing as you are not I think that is why iti s asking for an object. do you have the class setup correctly? like Class some_name { and then do the initialization of it.
then you connect to it like
$loads = new DBSQL();
$loads->setCurrentPage($curPage);
or something like that.hehe....actually this one got me thinking a bit and then I noticed that your error message is a bit of a Red Herring. You see, the reason your unable to unserialize is because PHP thinks $skim is empty! You know why? Because you haven't coded for register_globals being off and I can see that you dynamically construct a html anchor link in which the serialized data is given. When the resultant link is clicked it takes you to a page which should read the value of $skim from the HTTP GET (provided by the query line in the link) and unserialize your object.
So, after all that blurb, how do you get round it? Simple, replace this lineif(isset($skim)) { $skimObj = unserialize($skim); }with thisif(isset($_GET['skim'])) { $skimObj = unserialize($_GET['skim']); }That's my theory anyway. You should make sure that there are no other vars being passed by URI, if there are then you should change them also for $_GET['varname']. Give it a go and let me know if I am completely and utterly barking up the wrong tree hehe ruff ruff, why didn't I see that torrent, I'm sorry to say, but register_globals is ON. If PHP would think that $skim is empty it would go into the else-branch and construct a new skim object, at least I wouldn't get that error message.
Nevertheless I though I should give your solution a try, but using $_GET produced the same error.
scoutt, if I have messed up the class definition, why is it working perfectly on my local machine?
I still believe that $skimObj = unserialize($skim); does not construct the object correctly. Next thing I'll do is some kind of "object dump" from $skim to see what actually reaches the pages, maybe this will help. I'll post the result...I found the problem.
When $skim ist passed by the link through HTTP GET, backslashes are added to the quotation marks and thus the object cannot be constructed correctly on the target page.
So what I did is this (I even used $_GET since it is the preferable way to extract the values):
if(isset($_GET['skim']))) {
$skimObj = unserialize(stripslashes($_GET['skim'])));
}
Stripping the backslashes does the job.
thx for your support scoutt and torrent, greetings alk
There I always get a "Fatal error: Call to a member function on a non-object" error.
My frustration level is running high, so any help is truly appreciated, thx alk what is the cod eyou are using? I never had a problem with serialize on a unix box.I have a class called skim (for skim through ...) that has the following member function (just an excerpt):
function showNavigation($dest_page, $link_style, $session_id) {
$skim_serialized = serialize($this);
...
if (0 != $this->m_curPage) {
echo "<A class='$link_style' HREF='http://www.htmlforums.com/archive/index.php/$dest_page?curPage=" .($this->m_curPage-1);
echo "&skim=$skim_serialized$session_id'>";
echo "Previous </A>\n";
}
...
}
all this is in an file called skim.inc.php
Now the file where I use the stuff:
<?php
include("connect.inc.php");
include("../skim.inc.php");
$SID = connect_to_mysite();
session_register("sesUserID", "sesUserName", "sesUserRights");
if (!isset($sesUserID)) header("Location: connect.php?doAuth=1");
if(SID) {
$sid1 = "?" . SID;
$sid2 = "&" . SID;
}
// check if information to skim through the result pages has been sent
if(isset($skim)) { $skimObj = unserialize($skim); }
else { $skimObj = new skim(20); }
// set the number of the current page
if (isset($curPage)) { $skimObj->setCurrentPage($curPage); }
...
The error comes when setCurrentPage() is called. I tried using urlencode/urldecode and base64_encode/base64_decode on the serialized string, but that didn't help. where is the function setCurrentPage()The function is part of the skim class like showNavigation(). Actually it does not to much - see for yourself:
function setCurrentPage($curPage) { $this->m_curPage = $curPage; }
The problem is that the object (skimObj) is not correctly created when calling unserialize (I guess).well from my understanding of classes is that anytime you have $var->something) it usually menas you are working in a class. but seeing as you are not I think that is why iti s asking for an object. do you have the class setup correctly? like Class some_name { and then do the initialization of it.
then you connect to it like
$loads = new DBSQL();
$loads->setCurrentPage($curPage);
or something like that.hehe....actually this one got me thinking a bit and then I noticed that your error message is a bit of a Red Herring. You see, the reason your unable to unserialize is because PHP thinks $skim is empty! You know why? Because you haven't coded for register_globals being off and I can see that you dynamically construct a html anchor link in which the serialized data is given. When the resultant link is clicked it takes you to a page which should read the value of $skim from the HTTP GET (provided by the query line in the link) and unserialize your object.
So, after all that blurb, how do you get round it? Simple, replace this lineif(isset($skim)) { $skimObj = unserialize($skim); }with thisif(isset($_GET['skim'])) { $skimObj = unserialize($_GET['skim']); }That's my theory anyway. You should make sure that there are no other vars being passed by URI, if there are then you should change them also for $_GET['varname']. Give it a go and let me know if I am completely and utterly barking up the wrong tree hehe ruff ruff, why didn't I see that torrent, I'm sorry to say, but register_globals is ON. If PHP would think that $skim is empty it would go into the else-branch and construct a new skim object, at least I wouldn't get that error message.
Nevertheless I though I should give your solution a try, but using $_GET produced the same error.
scoutt, if I have messed up the class definition, why is it working perfectly on my local machine?
I still believe that $skimObj = unserialize($skim); does not construct the object correctly. Next thing I'll do is some kind of "object dump" from $skim to see what actually reaches the pages, maybe this will help. I'll post the result...I found the problem.
When $skim ist passed by the link through HTTP GET, backslashes are added to the quotation marks and thus the object cannot be constructed correctly on the target page.
So what I did is this (I even used $_GET since it is the preferable way to extract the values):
if(isset($_GET['skim']))) {
$skimObj = unserialize(stripslashes($_GET['skim'])));
}
Stripping the backslashes does the job.
thx for your support scoutt and torrent, greetings alk