I have a php class like,
<?php
namespace app\test;
class TestObject
{
private $obj_id;
private $obj_name;
public function __construct($obj_id, $obj_name)
{
$this->obj_id = $obj_id;
$this->obj_name = $obj_name;
}
public function get_obj_id()
{
return $this->obj_id;
}
public function get_obj_name()
{
return $this->obj_name;
}
}
And in my index.php I am trying to create a TestObject
and json encode it with,
$obj_1 = new TestObject(1, "testname");
echo json_encode($obj_1);
But as output I get only {}
Any idea, why it is not showing object fields?