Skip to content

Allow cast to be used in constant expressions #18261

Closed
@mvorisek

Description

@mvorisek

Description

repro: https://3v4l.org/OVu3r

<?php

declare(strict_types=1);

class Foo
{
    public const MAX_LARGE_LENGTH_BYTES = 1024 + 1; // 1 KiB + 1 %
    public const MAX_LARGE_LENGTH_BYTES2 = (int) (1024 * 1.01);
}

var_dump(Foo::MAX_LARGE_LENGTH_BYTES);
var_dump(Foo::MAX_LARGE_LENGTH_BYTES2);

Currently + is supported, but cast is not. But all of these are operators with constant result /wo side effects where the arguments are constant.

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