]> granicus.if.org Git - php/commitdiff
Fixed bitwise operations with numeric unicode strings
authorDmitry Stogov <dmitry@php.net>
Wed, 27 Jun 2007 11:04:50 +0000 (11:04 +0000)
committerDmitry Stogov <dmitry@php.net>
Wed, 27 Jun 2007 11:04:50 +0000 (11:04 +0000)
Zend/tests/and_001.phpt
Zend/tests/bug41640.phpt
Zend/tests/not_001.phpt
Zend/tests/or_001.phpt
Zend/tests/xor_002.phpt
Zend/zend_operators.c

index 109b2ce9952f74750af447b7b57f4f00519f63ed..c793828c21199417d08b134781900d4a638993f6 100644 (file)
@@ -3,28 +3,28 @@ bitwise AND and strings
 --FILE--
 <?php
 
-$s = "123";
-$s1 = "234";
+$s = b"123";
+$s1 = b"234";
 
 var_dump($s & $s1);
 
-$s = "test";
-$s1 = "some";
+$s = b"test";
+$s1 = b"some";
 
 var_dump($s & $s1);
 
-$s = "test long";
-$s1 = "some";
+$s = b"test long";
+$s1 = b"some";
 
 var_dump($s & $s1);
 
-$s = "test";
-$s1 = "some long";
+$s = b"test";
+$s1 = b"some long";
 
 var_dump($s & $s1);
 
-$s = "test";
-$s &= "some long";
+$s = b"test";
+$s &= b"some long";
 
 var_dump($s);
 
index c859d90850d665774fbe70c6bcadbf6104b72f69..11ef334f457b0cd24cdd6e7d6f2e84c46231eaff 100644 (file)
@@ -13,3 +13,8 @@ array(1) {
   ["x"]=>
   int(1)
 }
+--UEXPECT--
+array(1) {
+  [u"x"]=>
+  int(1)
+}
index 6eb0f000c90fb7808dd84425b457001680c0f971..0a6f0123b9e3b02d55bbe53f047f4a6f139d01fc 100644 (file)
@@ -5,8 +5,8 @@ bitwise NOT, doubles and strings
 
 $d = 23.67;
 $s = "48484.22";
-$s1 = "test";
-$s2 = "some";
+$s1 = b"test";
+$s2 = b"some";
 
 $s = ~$d;
 var_dump($s);
@@ -20,3 +20,7 @@ echo "Done\n";
 int(-24)
 string(8) "8c90929a"
 Done
+--UEXPECTF--   
+int(-24)
+unicode(8) "8c90929a"
+Done
index 1e4e5131a590ad674f14ee9980a8149da9cb5441..dbe8da111b8f50c2bfa431c9b1bd513ff4f793ec 100644 (file)
@@ -3,19 +3,19 @@ bitwise OR and strings
 --FILE--
 <?php
 
-$s = "323423";
-$s1 = "2323.555";
+$s = b"323423";
+$s1 = b"2323.555";
 
 var_dump($s | $s1);
 var_dump($s1 | $s);
 
-$s = "some";
-$s1 = "test";
+$s = b"some";
+$s1 = b"test";
 
 var_dump($s | $s1);
 
-$s = "some";
-$s |= "test";
+$s = b"some";
+$s |= b"test";
 
 var_dump($s);
 
index 0cf4054fa4cb2c9548eb66c531502c0d2dae6e02..11e8bc93bd9c82323cd77c72f335fedfc875c5f7 100644 (file)
@@ -3,28 +3,28 @@ XORing strings
 --FILE--
 <?php
 
-$s = "123";
-$s1 = "234";
+$s = b"123";
+$s1 = b"234";
 var_dump(bin2hex($s ^ $s1));
 
-$s = "1235";
-$s1 = "234";
+$s = b"1235";
+$s1 = b"234";
 var_dump(bin2hex($s ^ $s1));
 
-$s = "some";
-$s1 = "test";
+$s = b"some";
+$s1 = b"test";
 var_dump(bin2hex($s ^ $s1));
 
-$s = "some long";
-$s1 = "test";
+$s = b"some long";
+$s1 = b"test";
 var_dump(bin2hex($s ^ $s1));
 
-$s = "some";
-$s1 = "test long";
+$s = b"some";
+$s1 = b"test long";
 var_dump(bin2hex($s ^ $s1));
 
-$s = "some";
-$s ^= "test long";
+$s = b"some";
+$s ^= b"test long";
 var_dump(bin2hex($s));
 
 echo "Done\n";
@@ -37,3 +37,11 @@ string(8) "070a1e11"
 string(8) "070a1e11"
 string(8) "070a1e11"
 Done
+--UEXPECTF--   
+unicode(6) "030107"
+unicode(6) "030107"
+unicode(8) "070a1e11"
+unicode(8) "070a1e11"
+unicode(8) "070a1e11"
+unicode(8) "070a1e11"
+Done
index e245150a624d8225eff9c3b42c8a7b2bb2ddeb12..50ed7b011bf9c3b4f2bcc85062ce59cce2fe5f4a 100644 (file)
@@ -1499,7 +1499,7 @@ ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
                Z_STRLEN_P(result) = result_len;
                return SUCCESS;
        }
-       if (Z_TYPE_P(op1) == IS_UNICODE || Z_TYPE_P(op2) == IS_UNICODE) {
+       if (Z_TYPE_P(op1) == IS_UNICODE && Z_TYPE_P(op2) == IS_UNICODE) {
                zend_error(E_ERROR, "Unsupported operand types");
                return FAILURE;
        }
@@ -1543,7 +1543,7 @@ ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
                return SUCCESS;
        }
 
-       if (Z_TYPE_P(op1) == IS_UNICODE || Z_TYPE_P(op2) == IS_UNICODE) {
+       if (Z_TYPE_P(op1) == IS_UNICODE && Z_TYPE_P(op2) == IS_UNICODE) {
                zend_error(E_ERROR, "Unsupported operand types");
                return FAILURE;
        }
@@ -1588,7 +1588,7 @@ ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
                return SUCCESS;
        }
 
-       if (Z_TYPE_P(op1) == IS_UNICODE || Z_TYPE_P(op2) == IS_UNICODE) {
+       if (Z_TYPE_P(op1) == IS_UNICODE && Z_TYPE_P(op2) == IS_UNICODE) {
                zend_error(E_ERROR, "Unsupported operand types");
                return FAILURE;
        }
@@ -1606,11 +1606,6 @@ ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
 {
        zval op1_copy, op2_copy;
 
-       if (Z_TYPE_P(op1) == IS_UNICODE || Z_TYPE_P(op2) == IS_UNICODE) {
-               zend_error(E_ERROR, "Unsupported operand types");
-               return FAILURE;
-       }
-
        zendi_convert_to_long(op1, op1_copy, result);
        zendi_convert_to_long(op2, op2_copy, result);
        Z_LVAL_P(result) = Z_LVAL_P(op1) << Z_LVAL_P(op2);
@@ -1623,11 +1618,6 @@ ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
 {
        zval op1_copy, op2_copy;
 
-       if (Z_TYPE_P(op1) == IS_UNICODE || Z_TYPE_P(op2) == IS_UNICODE) {
-               zend_error(E_ERROR, "Unsupported operand types");
-               return FAILURE;
-       }
-
        zendi_convert_to_long(op1, op1_copy, result);
        zendi_convert_to_long(op2, op2_copy, result);
        Z_LVAL_P(result) = Z_LVAL_P(op1) >> Z_LVAL_P(op2);