Session/serialization problem
Posted: Mon Jul 18, 2005 10:29 pm
I'm having a problem with serializing objects to store in a session. When I serialize, it appears like there are null characters in the strings, resulting in the data being truncated when I attempt to add it to the session.
The output in the browser appears similar to the following (except that the "\0" I show here actually displays as a square-ish character):
O:7:"Account":4:{s:17:"\0Account\0username";s:8:"mhuggins";s:18:"\0Account\0firstName";s:4:"Matt";s:17:"\0Account\0lastName";s:7:"Huggins";s:14:"\0Account\0email";s:17:"mhuggins@udel.edu";}
Thanks for any help anyone can offer...I've never encountered this before, and I can't figure out what's wrong. I really appreciate it![/b]
Code: Select all
<?
class Account {
private $username = NULL;
private $firstName = NULL;
private $lastName = NULL;
private $email = NULL;
public function __construct() {}
public function setUsername($username) {
$this->username = $username;
}
public function getUsername() {
return $this->username;
}
public function setFirstName($firstName) {
$this->firstName = $firstName;
}
public function getFirstName() {
return $this->firstName;
}
public function setLastName($lastName) {
$this->lastName = $lastName;
}
public function getLastName() {
return $this->lastName;
}
public function setEmail($email) {
$this->email = $email;
}
public function getEmail() {
return $this->email;
}
}
?>Code: Select all
<?
require_once("e;Account.inc"e;);
$account = new Account();
$account->setUsername("e;mhuggins"e;);
$account->setFirstName("e;Matt"e;);
$account->setLastName("e;Huggins"e;);
$account->setEmail("e;mhuggins@udel.edu"e;);
print(serialize($account));
?>O:7:"Account":4:{s:17:"\0Account\0username";s:8:"mhuggins";s:18:"\0Account\0firstName";s:4:"Matt";s:17:"\0Account\0lastName";s:7:"Huggins";s:14:"\0Account\0email";s:17:"mhuggins@udel.edu";}
Thanks for any help anyone can offer...I've never encountered this before, and I can't figure out what's wrong. I really appreciate it![/b]