Heya Johannes,

For some functions taking binary strings is critical for working nicely
with an automatic conversion in this case
  crc32(u"äöü")
and
  crc32(b"äöü")
would give completely different results depending on the runtime
encoding,

Yes - but why should the user have to do the casting? Why can't the function itself cast to binary when it has an 'S' modifier? Like, during zend_parse_parameters() for example? Whatever happened to keeping PHP simple?

relying on a implicit conversion there is most likely a bug
(at least for apps written with PHP 6 in mind).

Oh and I might probably also argue that
  crc32(u"äöü")
should give the crc32 of the internal representation (utf-16...) of the
string, which is a total wtf for the user then.

Nobody's asking to be able to cast it to unicode. I'm asking whether it's entirely necessary to force users to cast to binary all over the place, and a strict binary parameter spec looks like being one place where the cast could be done internally.

The correct solution is to make safe use of the "S" modifier and not
using it too much.

As binary casts are allowed in modern PHP versions I don't see this as
an issue, while such a cast isn't absolutely the best thing to do: I'd
go with unicode_encode() to be sure about the encoding being used,
everything else is prone to fail some time (some code changing
unicode.runtime_encoding for some random reason...)

You're telling me an explicit cast to binary could fail internally but not externally? That doesn't make a lot of sense somehow.

- Steph


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

Reply via email to