i am trying to pass an object from one page to another, a very simple object defines as follows:
class numbers {
var one;
var two;
function numbers() {
$this->one = 1;
$this->two = 4;
}
function add() {
$three = $this->one + $this->two;
return $three;
}
in my first php file i do the following:
file1: insert.php
<?
include 'numbers.php';
session_start();
$test = new numbers();
$_SESSION['sam'] = $test;
header("location: select.php");
?>
file2: select.php
<? start_session();
$sam = $_SESSION['sam'];
echo $sam->add();
?>
i get the following erro:
Fatal error: Unknown(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition numbers of the object you are trying to operate on was loaded before the session was started in F:\portsaidmall\test\session\select.php on line 18
now, i am sure that i included the class before i started the session, i also tried something like
echo $_SESSION['sam']->add();
i get the same error
i tried: $sam = &$_SESSION['sam']; and i still get the same error
i tried serializing, then storing the serialized string in a session, then reading the serialized string in the next page, unserialized it, and tried it as follows:
$test = new numbers();
$my = serialize($test);
$_SESSION['sam'] = $my
in the next page i do:
$sam = $_SESSION['sam'];
$numbers = unserialize($sam);
echo $numbers->add();
and still again, the same error.....
i m sorry for the long post, but i have been searching on this since last night, and i am out of ideas and places to look
thanks in advance
sam