Skip to content

Misleading error message for array unpacking of objects/enums in constant expression #9769

Closed
@TysonAndre

Description

@TysonAndre

Description

The following code:

<?php
const EXAMPLE = [...new ArrayObject()];

Resulted in this output:

Warning: Uncaught Error: Only arrays and Traversables can be unpacked in ...

But I expected this output (something along these lines) instead:

Warning: Uncaught Error: Cannot unpack Traversables in constant expression in ...

This should be improved in php 8.3

PHP Version

8.1+

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions