Skip to content

Integer arithmethic with large number variants fails #8778

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

Closed
cmb69 opened this issue Jun 14, 2022 · 1 comment
Closed

Integer arithmethic with large number variants fails #8778

cmb69 opened this issue Jun 14, 2022 · 1 comment

Comments

@cmb69
Copy link
Member

cmb69 commented Jun 14, 2022

Description

The following code:

<?php
$int = 0x100000000;
var_dump(
    $int,
    new variant($int) + 1
);

Resulted in this output:

int(4294967296)

Fatal error: Uncaught TypeError: Unsupported operand types: variant + int in %s:%d

But I expected this output instead:

int(4294967296)
int(4294967297)

PHP Version

PHP-8.0

Operating System

Windows x64

@cmb69
Copy link
Member Author

cmb69 commented Jun 14, 2022

Oh, but casting to string would work:

> php -r "var_dump((string) new variant(0x100000000));"
string(10) "4294967296"

cmb69 added a commit to cmb69/php-src that referenced this issue Jun 14, 2022
When casting a `variant` to `int`, we need to heed the proper `zval`
type, which is an signed 64bit integer on x64, while `VT_INT` is only
a signed 32bit integer.
@cmb69 cmb69 self-assigned this Jun 14, 2022
@cmb69 cmb69 closed this as completed in 651e0cc Jun 18, 2022
cmb69 added a commit that referenced this issue Jun 18, 2022
* PHP-8.0:
  Fix GH-8778: Integer arithmethic with large number variants fails
cmb69 added a commit that referenced this issue Jun 18, 2022
* PHP-8.1:
  Fix GH-8778: Integer arithmethic with large number variants fails
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
@cmb69 and others