Skip to content

foreach over an object from outside its class lists private and protected properties; php lists only the visible ones. #487

Closed

Description

@blacktrs

Summary

foreach over an object from outside its class lists private and protected properties; php lists only the visible ones.

Repro

<?php
class A { private int $p = 2; protected int $r = 4; public int $q = 3; }
$k = [];
foreach (new A() as $n => $x) { $k[] = $n; }
echo json_encode($k), "\n";

Expected (php)

["q"]

Actual (manticore ece31242, Darwin arm64)

["p","r","q"]

Tracking

Known-bug repro: tests/aot/repro/wrong/foreach_object_lists_private.php — bash tests/aot/xfail.sh -k foreach_object_lists_private 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 Oct 26, 2026
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