Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow cast to be used in constant expressions #18261

Closed
mvorisek opened this issue Apr 6, 2025 · 1 comment · Fixed by #18264
Closed

Allow cast to be used in constant expressions #18261

mvorisek opened this issue Apr 6, 2025 · 1 comment · Fixed by #18264

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Apr 6, 2025

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.

@nielsdos
Copy link
Member

nielsdos commented Apr 6, 2025

I think this makes sense. I'll think a bit about it and maybe provide a patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants