Skip to content

Handling of JSON_THROW_ON_ERROR with optional bitwise flags #6654

@Seldaek

Description

@Seldaek

Bug report

When using a conditional path to build up the flags passed to json_encode, the JSON_THROW_ON_ERROR handling fails

Code snippet that reproduces the problem

https://phpstan.org/r/2c2248a1-cbf9-45b1-a346-85f0aca891fb

Expected output

string return value in both cases

Fix

Somewhere in https://github.com/phpstan/phpstan-src/blob/7667265bba564eb61711ad52376a6e7823708bda/src/Type/Php/JsonThrowOnErrorDynamicReturnTypeExtension.php#L85 it probably should handle the value as an int always, and simply check whether the int contains the bits from JSON_THROW_ON_ERROR, instead of checking for the constant's name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions