Skip to content

intval() with negative base prefixed string does not detect base #13243

Open
@Girgias

Description

@Girgias

Description

The following code:

<?php
$s = "-0b11111111111111111111111111111111111111111111111111111111111111111111111111111";
$v1 = intval($s, 2);
var_dump($v1);
$v2 = intval($s);
var_dump($v2);
var_dump((int) $s);

Resulted in this output:

int(-9223372036854775808)
int(0)
int(0)

But I expected this output instead:

int(-9223372036854775808)
int(-9223372036854775808)
int(0)

Similarly, if we use $base = 16

Note the 0o prefix is not supported (which is what initially led me down this rabbit hole).

PHP Version

PHP 8.3

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