php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39954 ~ operator doesn't convert string to integer first
Submitted: 2006-12-26 15:39 UTC Modified: 2006-12-26 16:38 UTC
From: olafvdspek at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.0 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: olafvdspek at gmail dot com
New email:
PHP Version: OS:

 

 [2006-12-26 15:39 UTC] olafvdspek at gmail dot com
Description:
------------
The ~ operator doesn't appear to convert a string to an integer first, like most other operators do. This produces unexpected results of course.

Reproduce code:
---------------
$b = '0';
$b = ~$b;
printf('%s - %s<br>', $b, ord($b));
$b = 0;
$b = ~$b;
printf('%s - %s<br>', $b, ord($b));


Expected result:
----------------
-1 - 45
-1 - 45

Actual result:
--------------
? - 207
-1 - 45

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-26 15:58 UTC] tony2001@php.net
Yes, it does not convert strings to numbers and this is by design. It actualy runs the "bitwise not" operator on each character of the string.
 [2006-12-26 16:02 UTC] olafvdspek at gmail dot com
What's the rationale behind that design?
And when is it useful?
 [2006-12-26 16:38 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

It is done for instances when a bitmask is applied to a string 
(one character at a time).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 15:01:29 2024 UTC