Edit report at https://bugs.php.net/bug.php?id=61660&edit=1

 ID:                 61660
 Updated by:         larue...@php.net
 Reported by:        krtek4+php at gmail dot com
 Summary:            bin2hex(hex2bin($data)) != $data
 Status:             Open
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Debian Linux
 PHP Version:        5.4.1RC1
 Block user comment: N
 Private report:     N

 New Comment:

I think it's better to well document this.  or,  add a prepend '0' , I will 
make a 
patch for this.


Previous Comments:
------------------------------------------------------------------------
[2012-04-07 16:45:45] krtek4+php at gmail dot com

I'm aware that this is a problem with the internal reprensation of the binary 
value which has to be aligned on 8 bits.

But with the actual implementation, we are losing informations.

A possible solution would be to pad the binary data with 0 on the left and when 
converting back again to hex, remove the leading 0s.

At least, something should be said in the documentation about this shortcoming.

------------------------------------------------------------------------
[2012-04-07 15:46:35] krtek4+php at gmail dot com

Description:
------------
If you try to apply bin2hex on the result of hex2bin, when the length of the 
initial data is an odd number, the resulting data are not the same as the 
original.

$ php -v
PHP 5.4.1RC1 (cli) (built: Apr  6 2012 13:31:16) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies

This is the original Debian package present in sid on the 7th April 2012




Test script:
---------------
<?php

$data = '12345';
var_dump($data, bin2hex(hex2bin($data)));
// outputs :
// string(5) "12345"
// string(4) "1234"

Expected result:
----------------
The output should be the same. (ie 12345 both times)

Actual result:
--------------
string(5) "12345"
string(4) "1234"



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=61660&edit=1

Reply via email to