> This is because $foo is local to the member functions of the class.
> declare global $foo at the start of every function.
Ok thnx... it worked... but how do you then explain this?:
***********************************************
<?php
class TestClass {
var $foo;
function setFoo($bar) {
$this->foo = $bar;
}
function getFoo() {
return $this->foo;
}
}
class TestClass2 {
function TestClass2($state) {
global $obj;
if($state == "page2") {
print("TYPE: " . gettype($obj) . "<br />\n");
print($obj->getFoo());
session_destroy();
} else {
session_register("obj");
$obj =& new TestClass();
$obj->setFoo("Hello World!");
print("TYPE: " . gettype($obj) . "<br />\n");
print("<a href=\"?state=page2\">Click here</a>\n");
}
}
}
session_start();
new TestClass2($state);
?>
***********************************************
When I on "page1" print("TYPE: " . gettype($obj) . "<br />\n");
I get this output: TYPE: object
When I on "page2" print("TYPE: " . gettype($obj) . "<br />\n");
I get this output: TYPE: NULL
(and the linie saying print($obj->getFoo()); generates an error:
Fatal error: Call to a member function on a non-object in
/home/httpd/html/test/save_objects.php on line 27
(just so you know: I have no problems saving an object in the session when
it's done outside a class. It's when I do this from within a class that the
problem occurs)
/watson
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]