|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47164 uncomfortable (binary)char() append to binary string
Submitted: 2009-01-20 10:59 UTC Modified: 2010-06-13 19:01 UTC
From: lunter at interia dot pl Assigned: scottmac (profile)
Status: Wont fix Package: Unicode Engine related
PHP Version: 6CVS-2009-01-20 (snap) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
1 + 31 = ?
Subscribe to this entry?

 [2009-01-20 10:59 UTC] lunter at interia dot pl
uncomfortable (binary)char() append to a binary string

Reproduce code:


Expected result:
detect $b type as binary string and adding chr() in binary mode

like this:



Actual result:
adding chr() in unicode


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-21 11:12 UTC]
Actually we need a function doing "binary chr" - chr() in PHP 6 takes a codepoint not the byte value, so  (binary)chr($c) will give the wrong result.
 [2009-01-21 11:26 UTC]
$b = sprintf("%c%c%c", 255, 254, 253);

should work, but having a simple function might still be helpful
 [2009-01-21 12:31 UTC] lunter at interia dot pl "(binary)chr($c) will give the wrong result"

hmmmmmmm....... try code above.

b1.dat consists utf-8 data
b2.dat consists binary chars 0 - 255 step 1, file length is correct - 256B & chars are correct...

 if(substr(phpversion(),0,1)!='6'){trigger_error('only PHP 6',E_USER_ERROR);}

// unicode.semantics = off
// unicode.runtime_encoding = iso-8859-1
// unicode.script_encoding = utf-8
// unicode.output_encoding = utf-8
// unicode.from_error_mode = U_INVALID_SUBSTITUTE
// unicode.from_error_subst_char = 3f


 [2009-01-21 16:24 UTC]
Scott said he'd look into this :-)
 [2010-06-13 19:01 UTC]
-Status: Assigned +Status: Wont fix
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon May 23 12:03:33 2022 UTC