php / php/php-src

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

未关闭
#13,243 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Extension: standard Status: Verified
主要语言
C
星标
40.4k
派生
8.2k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先复现使用 intval() 处理带有 0b 前缀的负数字符串的 PHP 8.3 示例,并比较显式基数 2、隐式基数检测和整数转换。完成的标准是确定并测试隐式基数检测是否应当生成与显式基数情况相同的饱和负整数,同时保留文档中所述的不支持 0o。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
backend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。