ID:               18680
 Updated by:       [EMAIL PROTECTED]
 Reported By:      su-php at bossi dot com
-Status:           Open
+Status:           Analyzed
 Bug Type:         Strings related
 Operating System: Win2K
 PHP Version:      4.1.2
 New Comment:

<?php
var_dump(ord(chr(32) | chr(64)));
var_dump(32 | 64);
var_dump(ord(chr(127) & (chr(32) | chr(16))));
var_dump(127 & (32 | 16));
var_dump("ABC" | " bc"); // should result in "abc"
?>

If a bitwise operation are performed between two string nodes, that
ends up with the results of that operation of the values of each
character's character codes.


Previous Comments:
------------------------------------------------------------------------

[2002-08-01 15:22:00] su-php at bossi dot com

It is not a session related problem, but a string conversion problem.
Below is a script which shows the problem. When doing test, remember
that the values should be based on a power of two, that is: 0x01, 0x02,
0x04, 0x08, 0x10, 0x20, ...
-------------------------
<html><head></head><body>
<h1>ORing Values</h1>
<?
do_table( 1, '1', 8, '8' );
do_table( 2, '2', 8, '8' );
do_table( 2, '2', 4, '4' );
do_table( 2, '2', 16, '16' );
do_table( 1, '1', 16, '16' );
?>
</body></html>

<?
function do_table( $val_1_num, $val_1_txt, $val_2_num, $val_2_txt )
{
?>
<br>
<table border="1">
<tr>
        <th></th>
        <th>Value 1</th>
        <th>Value 2</th>
        <th>Raw OR</th>
        <th>strval OR</th>
        <th>0+ OR</th>
</tr>
<tr>
        <td>Number</td>
        <td align="center"><?= $val_1_num ?></td>
        <td align="center"><?= $val_2_num ?></td>
        <td align="center"><?= $val_1_num | $val_2_num ?></td>
        <td align="center"></td>
        <td align="center"><?= (0 + $val_1_num) | (0 + $val_2_num) ?></td>
</tr>
<tr>
        <td>Text</td>
        <td align="center"><?= $val_1_txt ?></td>
        <td align="center"><?= $val_2_txt ?></td>
        <td align="center"><?= $val_1_txt | $val_2_txt ?></td>
        <td align="center"><?= strval($val_1_txt) | strval($val_2_txt)
?></td>
        <td align="center"><?= (0 + $val_1_txt) | (0 + $val_2_txt) ?></td>
</tr>
</table>
<?}?>

-------------------------

------------------------------------------------------------------------

[2002-07-31 18:57:18] [EMAIL PROTECTED]

Please add a short but COMPLETE example script which clearly
demonstrates the problem. 



------------------------------------------------------------------------

[2002-07-31 15:03:38] su-php at bossi dot com

I stated that strval() does not work. However a kludge that DOES work
is:

echo "Val : ".((0 + $opt['time']) | (0 + $opt['date']));

------------------------------------------------------------------------

[2002-07-31 14:53:07] su-php at bossi dot com

PHP version 4.1.1 (Hey it's an internal test bed, no outside
connection)

I am saving user options in an array. The array is then saved to the
session.

the basic variables are:
$TIME_FORMAT_12 = 0x01;
$TIME_FORMAT_24 = 0x02;
$DATE_FORMAT_YMD = 0x04;
$DATE_FORMAT_MDY = 0x08;
$DATE_FORMAT_DMY = 0x10;
$opt['time'] = $TIME_FORMAT_24;
$opt['date'] = $DATE_FORMAT_DMY;

At this point, the array holds numeric values. Now $opt[] is saved to
the session. When it is read back in, I believe the two values are no
longer numeric.

If you OR the base values:
 echo "Val: ".($TIME_FORMAT_24 | $DATE_FORMAT_DMY);
 echo "Val: ".($opt['time'] | $opt['date');
you get 18 or 0x12.

However if you OR the $opt values _after_ they have been retrieved from
the session:
 echo "Val: ".($opt['time'] | $opt['date');
you get 36.

I have tried (strval($opt['time']) | strval($opt['date'))) but it still
fails.

I am using the composite value to perform a logical AND to obtain the
settings: if ( $format_in & $DATE_FORMAT_DMY ) within a function.

------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=18680&edit=1

Reply via email to