Hei,
I committed a patch to make ord()
work on IS_BINARY strings earlier
today (http://news.php.net/php.cvs/33862). Andrei doesn't like that
because the description in the docs says "ord -- Return ASCII value of
character", which in his opinion doesn't make much sense for binary
strings. Other then ord()
, there is no suitable function to show the
ordinal value of a byte in a IS_BINARY string though. Comments?
Derick
--
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org
It makes perfect sense to me that ord()
would work on binary strings.
When we return an ASCII value we don't limit the range returned, it can
be 1 or 255. So, I see no reason to cripple this function and prevent it
from working on binary data.
Ilia
It makes perfect sense to me that
ord()
would work on binary strings.
When we return an ASCII value we don't limit the range returned, it can
be 1 or 255. So, I see no reason to cripple this function and prevent it
from working on binary data.
Indeed, the only thing is that you can't really talk about "ASCII"
values, as binary data doesn't really have an encoding (and certainly
not ascii as that's 7bits only). But IMO that's something to tune in the
docs.
Derick
--
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org
Did Andrei have a reason besides the docs? Even without
IS_UNICODE/IS_BINARY it sounds like the docs could use tuning anyway, no?
Andi
At 12:55 PM 9/8/2005, Derick Rethans wrote:
Hei,
I committed a patch to make
ord()
work on IS_BINARY strings earlier
today (http://news.php.net/php.cvs/33862). Andrei doesn't like that
because the description in the docs says "ord -- Return ASCII value of
character", which in his opinion doesn't make much sense for binary
strings. Other thenord()
, there is no suitable function to show the
ordinal value of a byte in a IS_BINARY string though. Comments?Derick
--
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org
Did Andrei have a reason besides the docs? Even without IS_UNICODE/IS_BINARY
it sounds like the docs could use tuning anyway, no?
Andrei: The docs say "Return ASCII value of character", which doesn't
make sense for binary. You can use bin2hex()
, bin2hex()
== ord()
for binary.
(Which is not true, as it doesn't return the ordinal value, just a two
digit hex string)
Derick: anyway, ord()
always worked on string like this, seems
strange to break it (and yes, it already did)
Andrei: you had binary strings before?
Derick: normal strings of course, but it came from a file, so it turned
binary and ord()
started failing
Andrei: Then you should fix your code and convert that binary to
something sensible if you are reading text
Derick: it's not text, it's binary
Andrei: if it's binary, why do you need to know the ascii value
Derick: Because I'm converting a binary file to a C file (for the
timezone database)
Then he continues saying that it's Ok to break BC in unicode mode.
regards,
Derick
--
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org
My argument was that ord()
semantics and docs say that it works on
characters and this simply does not make sense for the binary
strings. If we really want ord()
to work on binary type, fine, but
we'd better have docs that make sense then.
-Andrei
Did Andrei have a reason besides the docs? Even without IS_UNICODE/
IS_BINARY
it sounds like the docs could use tuning anyway, no?Andrei: The docs say "Return ASCII value of character", which doesn't
make sense for binary. You can usebin2hex()
,bin2hex()
==
ord()
for binary.(Which is not true, as it doesn't return the ordinal value, just a two
digit hex string)Derick: anyway,
ord()
always worked on string like this, seems
strange to break it (and yes, it already did)
Andrei: you had binary strings before?
Derick: normal strings of course, but it came from a file, so it
turned
binary andord()
started failingAndrei: Then you should fix your code and convert that binary to
something sensible if you are reading text
Derick: it's not text, it's binary
Andrei: if it's binary, why do you need to know the ascii value
Derick: Because I'm converting a binary file to a C file (for the
timezone database)Then he continues saying that it's Ok to break BC in unicode mode.
regards,
Derick--
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org
Andrei Zmievski wrote:
My argument was that
ord()
semantics and docs say that it works on
characters and this simply does not make sense for the binary
strings. If we really wantord()
to work on binary type, fine, but we'd
better have docs that make sense then.
IMHO the docs say characters because up until now, a character was
equivalent to a single byte in PHP. I think this is a documentation
snafu, that should be addressed by updating the docs accordingly.
Ilia