Skip to content

Too big string to int cast results nonsense #19118

Open
@kkmuffme

Description

@kkmuffme

Description

The following code:

<?php
if ( (string) PHP_INT_MAX === '9223372036854775808' ) {
    echo "string identical" . PHP_EOL;
}

if ( PHP_INT_MAX === (int) '9223372036854775808' ) {
    echo "int identical" . PHP_EOL;
}

Resulted in this output:

int identical

But I expected this output instead:

Deprecated: Conversion from string '9223372036854775808' to int loses precision

A very similar error already exists when converting float to int implicitly e.g. $a[ PHP_INT_MAX + 1 ] = '';

See also #17081 which reports that for float/int casts

PHP Version

PHP 8.4.8

Operating System

No response

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