ID: 32142 Updated by: [EMAIL PROTECTED] Reported By: ben dot ward at gmail dot com -Status: Open +Status: Bogus Bug Type: Strings related Operating System: Red Hat PHP Version: 4.3.10 New Comment:
I'd be very worried if that output anything else that 'Array', perhaps you should try this with latest snapshot: # sapi/cli/php -r 'var_dump(unpack("H*", "ABCD"));' Where it works just fine. (hint: try search next time before reporting same issue: See bug #31465) Previous Comments: ------------------------------------------------------------------------ [2005-03-01 01:17:56] ben dot ward at gmail dot com Description: ------------ See bug #31247 I've got a similar problem only I'm using 4.1.2, and phpinfo reports "Linux tweety.build.redhat.com 2.6.9-1.906_ELsmp #1 SMP Sun Dec 12 22:58:08 EST 2004 i686 unknown" This code used to work before our sysadmin patched the server: $packet = unpack("H*", $packet); after the patch I got the same warning "Type H: outside of string" I downloaded the source to 4.3.10 and discovered that due to the way it's written, H* will generate that warning and abort early. here is a workaround for the same code fragment $packet = unpack("H".(strlen($packet) * 2), $packet); $packet[""] = $packet[1]; unset($packet[1]); the problem isn't with the curly braces on the case, it's with the size variable and this if *after* the switch inputpos += size; if (inputpos < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Type %c: outside of string", type); inputpos = 0; } when this piece of code is hit with "H*" inputpos = 0, and size = -1 because H is the first specifier, and size is set to -1 to represent * in this piece of code case 'H': size = (arg > 0) ? arg / 2 : arg; arg = 1; break; If I get time this weekend I'll post a fix, hope this helps Thanks, Ben M. Ward ps the source file I downloaded was http://us4.php.net/distributions/php-4.3.10.tar.gz and the source file I walked through was php-4.3.10/ext/standard/pack.c function PHP_FUNCTION(unpack) Reproduce code: --------------- <?php echo unpack("H*", "ABCD"); ?> Expected result: ---------------- 41424344 Actual result: -------------- Warning: Type H: outside of string in /var/www/tsadmind/development/test.php on line 2 Array ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=32142&edit=1