About jsonSerialize()
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
Research direction
Read src/Json.php around processObject() and the linked jsonSerialize() implementation, then compare that behavior with PHP's JsonSerializable contract. Trace the existing processing path and its backward-compatibility implications; done means the intended behavior and BC decision are settled and covered for the chosen outcome.
Written by the indexing model from the issue text.
Description
About jsonSerialize()
PHP documentation mentions: Returns data which can be serialized by json_encode()
processObject() should return the result of jsonSerialize() without processing:
private static function processObject(object $data)
{
if ($data instanceof JsonSerializable) {
return $data->jsonSerialize();
}
...
}
But this will break BC.
If it is requered to pre-process data for JsonSerializable, this should be done inside jsonSerialize():
class SomeClass implements JsonSerializable
{
...
public function jsonSerialize(): mixed
{
return Json:process($this->data);
}
...
}
| Q | A |
|---|---|
| Is bugfix? | ✔️ |
| New feature? | ❌ |
| Breaks BC? | ✔️ |
- Dominant language
- PHP
- Stars
- 29
- Forks
- 9
- Avg merge
- 56m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from yiisoft/json
-
status:under discussion type:feature
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·