Skip to content

Destruct order of globals at normal script end differs from php #45

Open

Description

@blacktrs

Summary

Destruct order of globals at normal script end differs from php.

Repro

<?php
final class D { public function __construct(public string $n) {} public function __destruct() { echo $this->n, "\n"; } }
$b = new D('b');
$a = new D('a');
$c = new D('c');
function f(): void { $l = new D('local'); exit(0); }
f();

Expected (php 8.5)

local
c
a
b

Actual (manticore 10affa68, macOS arm64)

b
a
c
local

Tracking

Known-bug repro: tests/aot/repro/wrong/global_destruct_order.php — bash tests/aot/xfail.sh -k global_destruct_order 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 5, 2026
  2. added
    area:runtime
    on Oct 13, 2026
  3. blacktrs commented on Oct 13, 2026

    @blacktrs
    ContributorAuthor

    Partial (branch fix/batch-b, 576261b). Normal script end FIXED: OwnershipFlow drops main-scope objects in reverse declaration order (test global_destruct_order_normal_end). Still open: the exit() part of the repro (php destroys the function's locals first, then globals in reverse). exit() skips scope drops and the shutdown sweep runs in creation order. A reverse sweep on exit was tried and reverted: it broke dtor_shutdown_exit, where static-prop objects must stay in creation order. Real fix: exit() must unwind frames (run scope drops) before the sweep. Keep this issue open; the commit does not close it.

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

    area:runtimebugwrong-answer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions