I have the following piece of code.
class SomeClass
{
public static $one = 1;
private static $two = 2;
public $three = 3;
private $four = 4;
}
header("Content-Type: application/json");
echo json_encode(new SomeClass());
What I want to achieve is encode the public class property and member as a JSON object. My problem is that json_encode()
ignores public static $one = 1;
and the result will be:
{
"three": 3
}
Although I expect it to print the public static member as well, such as:
{
"one": 1,
"three": 3
}
Can JSON encoding be done with static members in PHP?