From 7e378e46ef9fd12ecf28398e164d446a9cb8655b Mon Sep 17 00:00:00 2001 From: Chris Wright Date: Tue, 15 Apr 2014 09:46:11 +0000 Subject: [PATCH] Improved information on behaviour of bitwise operators on string operands git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@333319 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/operators.xml | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/language/operators.xml b/language/operators.xml index 242b9184f9..9f2100661e 100644 --- a/language/operators.xml +++ b/language/operators.xml @@ -611,9 +611,22 @@ $o = &new C; then the equivalency. - Be aware of data type conversions. If both the left-hand and - right-hand parameters are strings, the bitwise operator will - operate on the characters' ASCII values. + If both operands for the &, | and + ^ operators are strings, then the operation will be + performed on the ASCII values of the characters that make up the strings and + the result will be a string. In all other cases, both operands will be + converted to integers + and the result will be an integer. + + + If the operand for the ~ operator is a string, the + operation will be performed on the ASCII values of the characters that make + up the string and the result will be a string, otherwise the operand and the + result will be treated as integers. + + + Both operands and the result for the << and + >> operators are always treated as integers. @@ -1165,10 +1178,14 @@ Expression: 0 = -4 << 62 - Don't right shift for more than 32 bits on 32 bits systems. - Don't left shift in case it results to number longer than 32 bits. - Use functions from the gmp extension for bitwise manipulation on - numbers beyond PHP_INT_MAX. + Shifting integers by values greater than or equal to the system long + integer width results in undefined behavior. In other words, don't shift + more than 31 bits on a 32-bit system, and don't shift more than 63 bits on + a 64-bit system. + + + Use functions from the gmp extension for + bitwise manipulation on numbers beyond PHP_INT_MAX.