Skip to content

Allow json_decode() to return an ArrayObject #3382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

duncan3dc
Copy link
Member

This adds a new flag JSON_AS_ARRAY_OBJECT for json_decode(), to have it return the result as an ArrayObject instead of stdClass. This is so that it conforms to the iterable type hint.

function iter(iterable $items)
{
    foreach ($items as $key => $item) {
        echo "[{$key}] = '{$item}'" . PHP_EOL;
    }
}

$result = json_decode('{"one": "1", "two": "2"}', false, 512, JSON_AS_ARRAY_OBJECT);
iter($result);

I'll be drafting an RFC once the list is a little quieter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant