Closed
Description
Description
The following code:
<?php
class Example implements JsonSerializable
{
public function __construct(
private array $authors,
) {}
public string $credits {
get {
return implode(', ', $this->authors);
}
}
public function jsonSerialize():mixed{
return get_object_vars($this);
}
}
$obj = new Example(['test', 'test2']);
echo json_encode($obj);
Resulted in this output:
{"\u0000Example\u0000authors":["test","test2"],"credits":"test, test2"}
But I expected this output instead:
{"authors":["test","test2"],"credits":"test, test2"}
Without the getter it does serialize as expected:
The following code:
<?php
class Example implements JsonSerializable
{
public function __construct(
private array $authors,
) {}
public function jsonSerialize(): mixed
{
return get_object_vars($this);
}
}
Results in
{"authors":["test","test2"]}
PHP Version
master
Operating System
No response