yiisoft / yiisoft/json

About jsonSerialize()

Open
#44 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
29
Forks
9
Avg merge
56m
Merged PRs (30d)
1

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? ✔️

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

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.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.