On Tue, May 29, 2007 4:25 am, Antony Dovgal wrote:
> Hello.
>
> Do you think the engine should support bitwise operators and Unicode
> strings?
> If yes, how do you think it should work?
>
> Example:
> <?php
> $a = "1";
> $a|="2";
> var_dump($a);
> ?>
>
> This code outputs "3" in native mode and "Fatal error: Unsupported
> operand types" in Unicode mode.
> I believe this is an inconsistency and it should be possible to use
> Unicode strings there.

Given that there are probably a bazillion PHP scripts written by
newbies just like that, I'd have to say it's crucial for wide-spread
Unicode adoption for it to "just work"

> There are several possible ways to implement it:
> 1) the same as with native strings - apply the operator to each
> element of the string separately;
> 2) convert the string to binary (using say iso-8859-1) and then see
> 1);

How do you type-juggle Unicode strings now when they are used as
(int), regardless of the bit-wise operator or not?

Seems to me that you'd want the exact same operations as:
<?php
  $a = '1';
  $a += '2';
  var_dump($a);
?>

Doesn't seem like the bitwise operator is relevant, really...

> We can also leave it as is (since it doesn't seem very useful) or even
> drop the native strings support (it doesn't seem very useful to me
> either).
> Opinions?

Dropping support for the bazillion scripts that expected PHP to
type-juggle '2' into 2 and do math with them is probably a Bad Idea...

It's so bad, I must be missing something here, because I don't think
you'd suggest it... :-)

Ultimately, though, it seems like it should just do what PHP has
always done with that code, because if it doesn't, here's what'll
happen:

ISP turns on Unicode support.
Client scripts break.
ISP reverts to PHP 5, or PHP 4 even, or turns off Unicode support.

I am almost certain that I have code that does something not unlike:

<?php
  $value = 0;
  //read checkboxes
  foreach($_GET['flag'] as $flag){
    $value |= $flag;
  }
  //store $flag in DB as int
?>

I'm not claiming it's the Best Code Ever, but it's not exactly
Horrible either...

Seems like with Unicode turned "on" I'd still expect this to "work"
without throwing an (int) in there.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to