@Crell I may have miss it during Enum discussion but why can't in Backed Enum we do what is allowed for constants aka something along this line

enum MemoryUnit: int
{
case Byte = 1;
case Kilobyte = 1_024;
case Megabyte = 1_024 * 1_024;
case Gigabyte = 1_024 * 1_024 * 1_024;
case Terabyte = 1_024 * 1_024 * 1_024 * 1_024;
}

#PHP #Enum #questionoftheday

@Crell you can do this in Interfaces

interface MemoryUnit
{
public const Byte = 1;
public const Kilobyte = 1_024;
public const Megabyte = 1_024 * 1_024;
public const Gigabyte = 1_024 * 1_024 * 1_024;
public const Terabyte = 1_024 * 1_024 * 1_024 * 1_024;
}

@nyamsprod Er, that seems to work?

https://3v4l.org/Y0dc5

Y0dc5 - created on 3v4l.org

View the output of this script on 3v4l.org: the online PHP shell with 250+ PHP versions

@Crell PHPStorm is telling me otherwise ... I should have tested on 3v4l good advice ..
@nyamsprod Looks like. Phpstorm bug. Or maybe some plug-in.
@Crell not a plugin ... just PHPStorm bug

@nyamsprod @Crell It becomes a float on 32-bit systems because it's larger than the max int size.

The WASM build on PHP and 3v4l show a type error.

@zimzat @Crell good catch indeed 1_024 ** 4 is larger than PHP_INT_MAX on 32-bit systems. I still believe PHPStorm has a bug or at least should mention for which system the code would be erroneous.