Skip to content

Anonymous classes in two files of one namespace get the same anon_class_N symbol: invalid redefinition at link #536

Closed

Description

@samdark

Two anonymous classes in different files of the same namespace get the same symbol name, so the build fails when the IR is assembled.

src/App/A.php:

<?php
namespace App;
final class A { public static function make(): object { return new class { public function name(): string { return 'A'; } }; } }

src/App/B.php:

<?php
namespace App;
final class B { public static function make(): object { return new class { public function name(): string { return 'B'; } }; } }

src/main.php:

<?php
echo \App\A::make()->name(), \App\B::make()->name(), "\n";

manticore.json:

{"applications":[{"name":"anon","src":"src","output":"anon","entry":"src/main.php"}]}

Expected (php): AB

Actual (manticore build manticore.json):

error: invalid redefinition of function 'manticore_App___anon_class_0__name'
assemble: clang -c staged IR failed (rc=256)

The counter behind anon_class_N seems to be per file, while the name is built from the namespace only. Moving both classes into one file works.

Manticore 0.17.0 (ghcr.io/manticorephp/compiler:latest, image built 2026-10-24, Linux x86_64). PHP reference: 8.5.4.

Activity

  1. added
    bug
    crash
    area:runtime
    on Oct 30, 2026
  2. blacktrs commented on Oct 30, 2026

    @blacktrs
    Contributor

    Thanks for the bug report!
    This one will be fixed in the next release. A similar issue was recently found with closures, so it will be reused.
    The root cause is missing shared storage for anon class IDs during compilation.

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:runtimebugcrash

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions