3
PHP has a cast
(that until then I did not know), called binary
.
Example of Handbook:
$binary = (binary)$string;
$binary = b"binary string";
According to the PHP Handbook:
(Binary) - converts to binary string
I saw that a user still posted the following:
Cast a string to Binary using PHP < 5.2.1
(convert a string to binary in versions prior to PHP 5.2.1)
$binary = unpack('c*', $string);
With the test I performed in PHP 5.6, the result was as follows::
$string = "My String";
$binary = (binary)$string;
$binary = b"binary string";
var_dump($binary); // string(13) "binary string"
That is, returns the same value as the string (even with the cast for binary
).
The question is: is this functionality really available (being bug of my PHP) or it will just be a future implementation (as they say: "In PHP 6")?
As it says in the manual: (Binary) - converts to binary string (PHP 6)
– Jorge B.
@Jorgeb. only the doc in Portuguese is like this.
– gmsantos
@Jorgeb. It is because there is information where a user says: _"PHP 5.2.1 <". That is, it implies that it should already work
– Wallace Maxters
That’s right, @gmsantos. And there’s more "(Binary) casting and b prefix forward support was Added in PHP 5.2.1" it seems to me to sound like _"prefix support has been implemented
binary
, but it won’t work yet". kkkkk– Wallace Maxters
Here it seems that nothing happens to the string: http://sandbox.onlinephpfunctions.com/code/392dde9694e267a9d4e2e687e602e21097faa725
– Jorge B.
Let’s see now an official response. Let’s see what the manual people have to tell us in this Bug Reporting
– Wallace Maxters