Skip to content

json_encode() of an ArrayObject answers {} instead of its storage's elements. #589

Open

Description

@blacktrs

Summary

json_encode() of an ArrayObject answers {} instead of its storage's elements.

Repro

<?php
echo json_encode(new ArrayObject([1])), json_encode(new ArrayObject(['a' => 2])), "\n";

Expected (php)

{"0":1}{"a":2}

Actual (manticore ccab22c3, Darwin arm64)

{}{}

Tracking

Known-bug repro: tests/aot/repro/wrong/json_encode_arrayobject_empty.php — bash tests/aot/xfail.sh -k json_encode_arrayobject_empty reports XFAIL while this is open and XPASS once it is fixed; then move the repro into tests/aot/cases/ and close this issue.

Activity

  1. added
    bug
    wrong-answer
    on Nov 7, 2026
  2. blacktrs commented on Nov 12, 2026

    @blacktrs
    ContributorAuthor

    Root cause found during the #655 sweep (not fixed): (array) of an ArrayObject/ArrayIterator returns its internal slots (\0ArrayObject\0__s, …) instead of the storage, and json_encode goes through that cast. Two producers need the storage arm: the per-class __mir_ovars_<id>_mg helpers (EmitLlvmBuiltins::emitObjectVarsInline) and the descriptor-reached @__mir_props_<id> (the path the stdlib's json_encode takes, since the stdlib's class table never names a program's prelude classes). get_object_vars() already matches php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions