Hi all,
Since PHP-5.2.1 we have an artifact of PHP-6 in the engine means we can
define binary strings but such definitions haven't any effect.
So what we can define is the following:
$str = "str";
$bin = b"b\0i\0n";
$str2bin = (binary)$str;
One of the biggest issue is that currently ALL strings will be handled
as ASCII-7 compatible strings on type-juggling but they aren't.
It would be very appreciated if PHP could respect such binary declaration:
- use binary string comparison on compare a binary string to any other
string - don't convert binary strings into integers on array keys
- allow bitwise operators on binary strings without casting to integer
I don't wont to open such unicode nightmare as it was planned for PHP-6!
In my opinion the above operator changes are enough and therefore
internal functions doesn't need to be changed in the first place. The
only changes could be done to functions reading/parsing data to be
auto marked binary like: unpack, stream reading functions opened with
fopen + "b" ...
I don't have enough zend experience and therefore I would like to know
how complicated it would be.
Thoughts?
Marc
Hi,
Since PHP-5.2.1 we have an artifact of PHP-6 in the engine means we can define binary strings but such definitions haven't any effect.
Yes. That’s because PHP 6 was going to have Unicode strings by default, alongside binary strings (to PHP 5 and 7, just “strings”).
These “binary strings” are just strings.
So what we can define is the following:
$str = "str";
$bin = b"b\0i\0n";
$str2bin = (binary)$str;One of the biggest issue is that currently ALL strings will be handled as ASCII-7 compatible strings on type-juggling but they aren’t.
In the rare case you need to prevent type juggling of binary data, you could wrap it in an object.
It would be very appreciated if PHP could respect such binary declaration:
- use binary string comparison on compare a binary string to any other string
- don't convert binary strings into integers on array keys
- allow bitwise operators on binary strings without casting to integer
This would break existing code which was made “PHP 6-ready”.
Also, we already support bitwise operations on strings, I don’t know what you’re on about there...
--
Andrea Faulds
http://ajf.me/
Hi Andrea,
Am 08.02.2015 um 22:09 schrieb Andrea Faulds:
Hi,
Since PHP-5.2.1 we have an artifact of PHP-6 in the engine means we can define binary strings but such definitions haven't any effect.
Yes. That’s because PHP 6 was going to have Unicode strings by default, alongside binary strings (to PHP 5 and 7, just “strings”).These “binary strings” are just strings.
So what we can define is the following:
$str = "str";
$bin = b"b\0i\0n";
$str2bin = (binary)$str;One of the biggest issue is that currently ALL strings will be handled as ASCII-7 compatible strings on type-juggling but they aren’t.
In the rare case you need to prevent type juggling of binary data, you could wrap it in an object.
Wrapping all in objects isn't an option. This would only add unnecessary
overhead and only move the issue to a different place.
It would be very appreciated if PHP could respect such binary declaration:
- use binary string comparison on compare a binary string to any other string
- don't convert binary strings into integers on array keys
- allow bitwise operators on binary strings without casting to integer
This would break existing code which was made “PHP 6-ready”.
I don't think so. If a string was declared as binary it should be binary
else it is a wrong declaration and a bug.
Also, we already support bitwise operations on strings, I don’t know what you’re on about there...
Sorry I wasn't clear.
I mean the bitwise shift operators see http://3v4l.org/MBadR
... or as the other bitwise operators already works on all strings the
bitwise shifting operators should do so.
Like proposed in https://wiki.php.net/rfc/string-bitwise-shifts
@Chris status ?
--
Andrea Faulds
http://ajf.me/
Hi,
Wrapping all in objects isn't an option. This would only add unnecessary overhead and only move the issue to a different place.
I don’t see why not. Objects are generally exempt from type juggling, except for conversion to strings.
Surely that’s what you want?
This would break existing code which was made “PHP 6-ready”.
I don't think so. If a string was declared as binary it should be binary else it is a wrong declaration and a bug.
It already is binary, though. PHP’s strings are binary, they always have been. The reason that we have (binary) is because PHP 6 was going to make (string) a synonym of (unicode) instead.
Also, we already support bitwise operations on strings, I don’t know what you’re on about there...
Sorry I wasn't clear.
I mean the bitwise shift operators see http://3v4l.org/MBadR
That would be a BC break, and the kind of non-obvious evil one Derick doesn’t like much.
Though I can’t talk: I already ‘broke’ bitwise shifts with the Integer Semantics RFC.
--
Andrea Faulds
http://ajf.me/