Hi, Need some help about with Memcache.
I have created a class and want to store its objects in Memcache, finding trouble doing so please tell me where am I going wrong. Following is my code
// Class defined by me
class User
{
public $fname;
public $age;
/**
* @return unknown
*/
public function getfname() {
return $this->fname;
}
/**
* @return unknown
*/
public function getage() {
return $this->age;
}
/**
* @return unknown
*/
public function setfname() {
return $this->fname;
}
/**
* @return unknown
*/
public function setage() {
return $this->age;
}
}
//Code for Storing
<?php
$objMemcache = new Memcache();
$objMemcache->connect('127.0.0.1', 11211);
$obj = new User();
$obj->setfname('John');
$obj->setage(32);
$objMemcache->set('user1', $obj, false, 60);
$obj1 = new User();
$obj1->setfname('Doe');
$obj1->setage(23);
$objMemcache->set('user2', $obj1, false, 60);
var_dump($objMemcache->get('user1'));
?>
The problem is I am not able to make sure if the object is actually getting store in Memache coz when i try to retrieve it using the $objMemcache->get($key), the var_dump function prints nothing.
Please help.
Can you please explain the error in my code.
Thanks soulmerge, Frank and Kevin, the solution worked, just another doubt.
Making the class variables private worked fine but when i try to convert the class object into a JSON_STRING using json_encode() it gives me again an empty value, any suggestions on that