Skip to content

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

Closed

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

Activity

  1. cmb69 commented on Oct 18, 2022

    @cmb69
    Member

    Indeed, this error message is wrong. Given that there still will be two RCs for 8.2, it might make sense to fix it right away.

  2. jhdxr commented on Oct 18, 2022

    @jhdxr
    Member

    Indeed. For constant expression actually only arrays are accepted. This issue is shadowed coz new is not allowed before.

  3. jhdxr commented on Oct 18, 2022

    @jhdxr
    Member

    @cmb69 , I created a PR targeting 8.1 as this is indeed a bug and 8.1 is still in support. However if you believe this is a BC break that doesn't suitable for 8.1, feel free to change the target branch to 8.2.

  4. cmb69 commented on Oct 18, 2022

    @cmb69
    Member

    I'm unsure about which branch to target. There is a recent discussion on internals about unserialization where the point was made by some that changing an exception message would constitute a BC break, even for an Error exception.

  5. derickr commented on Oct 18, 2022

    @derickr
    Member
  6. jhdxr commented on Oct 19, 2022

    @jhdxr
    Member

    That's a silly thing. Message texts are not, and have never been considered stable.

    Personally I fully agree with you, but I did see the debatees on mail list as well. Anyway, I leave the PR open for RMs to decide which branch is suitable.

  7. cmb69 commented on Oct 19, 2022

    @cmb69
    Member

    Anyway, I leave the PR open for RMs to decide which branch is suitable.

    Then we should ask the RMs: @ramsey, @patrickallaert, @krakjoe, what do you think?

  8. ramsey commented on Oct 25, 2022

    @ramsey
    Member

    I'm okay with changing the error message.

  9. added 2 commits that reference this issue on Dec 2, 2022
    6b1f4c5
    9f0e4a5
  10. added a commit that references this issue on Mar 29, 2024
    93592ea
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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