php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47424 not operator does a C cast to long which is different to other ops
Submitted: 2009-02-17 14:05 UTC Modified: 2016-07-13 13:52 UTC
From: d_kelsey at uk dot ibm dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2CVS-2009-02-17 (CVS) OS: Linux 64Bit
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: d_kelsey at uk dot ibm dot com
New email:
PHP Version: OS:

 

 [2009-02-17 14:05 UTC] d_kelsey at uk dot ibm dot com
Description:
------------
In zend_operators.c the function ZEND_API int bitwise_not_function(..)
handles a double by doing a c cast to a long
"if (op1->type == IS_DOUBLE) {
	op1->value.lval = (long) op1->value.dval;
	op1->type = IS_LONG;
}"

but all other operators use the zendi_convert_to_long() macro
so not isn't consistent with the other operators.

this can result in an unexpected value as shown in the test case

Reproduce code:
---------------
<?php
define("MAX_64Bit", 9223372036854775807);
$e = (MAX_64Bit + 1);
$f = (int)$e;
var_dump(~(MAX_64Bit + 1));
var_dump(~$f);
?>


Expected result:
----------------
int(-9223372036854775808)
int(-9223372036854775808)

Actual result:
--------------
int(9223372036854775807)
int(-9223372036854775808)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-05 20:36 UTC] whatrevolution at yahoo dot com
Bug OP's test, result:

int 9223372036854775807
int 9223372036854775807


PHP Version 5.2.10-2ubuntu6.4

System 	Linux 2.6.31-20-generic x86_64
Build Date 	Jan 6 2010 22:36:47
Server API 	Apache 2.0 Handler 
PHP API 	20041225
PHP Extension 	20060613
Zend Extension 	220060519
Debug Build 	no
Thread Safety 	disabled
Zend Memory Manager 	enabled 

Apache/2.2.12 (Ubuntu)
 [2016-07-13 13:52 UTC] dmitry@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: dmitry
 [2016-07-13 13:52 UTC] dmitry@php.net
The bug was fixed long time ago in PHP-5.3.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 19:01:33 2025 UTC