#39954 [Opn->Bgs]: ~ operator doesn't convert string to integer first

From: Date: Tue, 26 Dec 2006 16:38:54 +0000
Subject: #39954 [Opn->Bgs]: ~ operator doesn't convert string to integer first
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-106898@lists.php.net to get a copy of this message
ID: 39954 Updated by: iliaa@php.net Reported By: olafvdspek at gmail dot com -Status: Open +Status: Bogus Bug Type: Scripting Engine problem Operating System: Windows XP PHP Version: 5.2.0 New Comment: 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). Previous Comments: ------------------------------------------------------------------------ [2006-12-26 16:02:43] olafvdspek at gmail dot com What's the rationale behind that design? And when is it useful? ------------------------------------------------------------------------ [2006-12-26 15:58:42] 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 15:39:45] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39954&edit=1

« previous php.bugs (#106898) next »