Bean.php
class Bean {
private $ename = '';
private $fathername='';
function getEname() {
return $this->ename;
}
function getFathername() {
return $this->fathername;
}
function setEname($ename) {
$this->ename = $ename;
}
function setFathername($fathername) {
$this->fathername = $fathername;
}
}
test.php
require 'Bean.php';
$finaldata = array();
$k = new Bean();
$k->setEname("Sahil Manchanda");
$k->setFathername("Pawan Kumar Manchadna");
$c = new Bean();
$c->setEname("Rahul Khurana");
$c->setFathername("Vijay Kumar Khurana");
$d = new Bean();
$d->setEname("Gourav Arora");
$d->setFathername("Mangat Rai Arora");
$finaldata[] = $k;
$finaldata[] = $c;
$finaldata[] = $d;
echo json_encode($finaldata);
output:
[{},{},{}]
it is not converting array to json. I had created a Bean Class which holds two parameters and then in other file i created three objects of bean class and then store it in an array. When i tried to encode this in JOSN it gives me three empty json array. please tell me what i did wrong.....