php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #25533 or with strings is wrong
Submitted: 2003-09-14 11:47 UTC Modified: 2003-09-16 15:31 UTC
From: spagmoid at yahoo dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: * OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: spagmoid at yahoo dot com
New email:
PHP Version: OS:

 

 [2003-09-14 11:47 UTC] spagmoid at yahoo dot com
Description:
------------
This is a difficult issue to search for dups on.  Strings used with pipe OR "|" do something weird.  Here it is:

echo "146"|"2";

result is "346"

echo (int)"146"|"2";

result is correct "146";


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-14 20:08 UTC] iliaa@php.net
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

Do not perform bitwise operations on strings.
 [2003-09-15 22:52 UTC] spagmoid at yahoo dot com
Uhh..

"do not"?  That's your solution?  You're kidding, right?

OK how about this.  Values returned from mysql.

$A = "146";
$B = "2";
echo $A|$B;
result: 346
 [2003-09-15 22:55 UTC] iliaa@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

echo (int)$A|(int)$B;
 [2003-09-15 23:15 UTC] spagmoid at yahoo dot com
if $A+$B works, then $A|$B should work as well.  '|' is not '.'
 [2003-09-16 11:19 UTC] wez@php.net
You can't logically OR strings.
Now, forget about it ;)
 [2003-09-16 11:25 UTC] spagmoid at yahoo dot com
Then why can you add strings with +?
Why can you logically AND strings with &?
Why can you multiply strings with *?
Does consistency matter in the slightest to you people?
 [2003-09-16 11:45 UTC] wez@php.net
We won't be changing this, because we don't see a need for performing bitwise logical operations on strings.

If you feel so strongly about it, you are welcome to submit a patch to the developer list and see if enough people think it's worthwhile including in PHP.

Please keep the status of this report as it is.
 [2003-09-16 12:36 UTC] spagmoid at yahoo dot com
If I leave the status as it is, noone will read it again.
I'm doing an article comparing idiosyncrasies of PHP vs ASP.  Can I get a statement from the PHP community along the lines of:

"It is the opinion of the PHP Community that ideally, bitwise AND should work on strings, and bitwise OR should not.  While this may appear tremendously stupid, it is actually quite logical and intelligent."
 [2003-09-16 13:25 UTC] abies@php.net
Here's your statement:

"PHP has two string operators ('.' and '.=', RTFM). The result of using other operators on strings is undefined."
 [2003-09-16 13:33 UTC] spagmoid at yahoo dot com
"The result of using other operators on strings is undefined."

RTFM??  That line isn't in the manual you moron!  You just made it up!  Add it to the manual then, instead of improving your product.  What a bunch of jackasses.

THIS is in the manual:

String conversion to numbers
When a string is evaluated as a numeric value, the resulting value and type are determined as follows.
 [2003-09-16 13:39 UTC] spagmoid at yahoo dot com
Let's see a few other things straight from the manual since you're all such EXPERTS on it:

$foo = "0";  // $foo is string (ASCII 48)
$foo += 2;   // $foo is now an integer (2)

$foo = 1 + "10.5";                // $foo is float (11.5)
$foo = 1 + "-1.3e3";              // $foo is float (-1299)
$foo = 1 + "bob-1.3e3";           // $foo is integer (1)
$foo = 1 + "bob3";                // $foo is integer (1)
$foo = 1 + "10 Small Pigs";       // $foo is integer (11)
$foo = 4 + "10.2 Little Piggies"; // $foo is float (14.2)
$foo = "10.0 pigs " + 1;          // $foo is float (11)
$foo = "10.0 pigs " + 1.0;        // $foo is float (11) 

Does that look "UNDEFINED" to you???  Huh?  Take that feature out and watch how many current PHP apps fail.  You people have no sense of QUALITY whatsoever.  NO PRIDE IN YOUR WORK.  NO PRIDE IN PHP.
 [2003-09-16 13:47 UTC] abies@php.net
And what, in your opinion, should be the result of
"10 Small Pigs" | "10.2 Little Piggies" ?

The point is that logical (bitwise) operations are inherently not loosely typed. That's why the logical operators are (and will remain) undefined on strings.
Use a cast at your own risk.

 [2003-09-16 14:10 UTC] brad at info-link dot net
In PHP:

"10 Small Pigs" | "10.2 Little Piggies"  = "10.smmm|t|mgsiggies"

Seems to follow the Perl way of doing things...  Each char in the first string is bitwise or'd with the corresponding char in the second string.

I didn't test bitwise-&, ^, etc, but I would expect them to act similarly.

Why not just add examples to the manual instead of saying it's undefined?  Why allow an operation that you can't depend on - just throw a compiler error.
 [2003-09-16 14:25 UTC] helly@php.net
It is a thing that is in our view a) illogical and b) we don't care about. Not to your question. If we were to produce an error message we could instead implement any behaviour with the same amount of work - but to repeat - we don't care about. Thus it is undefined. And since it is undefined we will not provide examples for what it does because that would make it a documented feature we would have to take care about - and just to repeat - we don't care about.
 [2003-09-16 15:31 UTC] spagmoid at yahoo dot com
That is the very problem - it's quite obvious that noone there cares about it.  No pride, like I said.

But it was obviously not illogical to the person who made it work with '&'.  Why isn't he here?  That's what this project desperately needs - code ownership.  When you divide programmers and bugfixers, you end up with a bunch of people who really DO not care.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 15:01:28 2024 UTC