note 11753 deleted from function.session-register by jimw

From: Date: Tue, 18 Dec 2001 22:26:40 +0000
Subject: note 11753 deleted from function.session-register by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-23263@lists.php.net to get a copy of this message
if you are going to use session variables containing instantiated classes, you must define the object in the pages where the object is referred to. More importantly, the definition of the object must precede the session_start() where it is referred to. <?php session_start(); session_register("foo"); class foo { var $bar } $foo=new foo; $foo->bar="test"; ?> WRONG: ===another page=== <?php session_start(); echo $foo; # prints 'Object' echo $foo->bar; # produces error message ?> WRONG: ===another page=== <?php session_start(); echo $foo; # prints 'Object' echo $foo->bar; # produces error message class foo{ var $bar } # can't define the class after referring to properties or methods within it ?> RIGHT: ===another page=== <?php class foo { var $bar } session_start(); echo $foo; # prints 'Object' echo $foo->bar; # prints "test" ?> for obvious reasons, its best to put your class definitions in a separate document, and include it in both documents.

« previous php.notes (#23263) next »