ID:               31465
 Updated by:       [EMAIL PROTECTED]
 Reported By:      php-bug-31247 at ryandesign dot com
-Status:           Open
+Status:           Verified
-Bug Type:         Unknown/Other Function
+Bug Type:         Strings related
-Operating System: N/A
+Operating System: *
-PHP Version:      5.0.3
+PHP Version:      4CVS, 5CVS (2005-01-10)


Previous Comments:
------------------------------------------------------------------------

[2005-01-10 05:38:02] php-bug-31247 at ryandesign dot com

I've analyzed the PHP 5.0.3 source code and believe I 
have identified the problem. Here's my following of the 
logic in /etc/standard/pack.c, given an unpack string 
like "H*hex":

- On line 540, variable "inputpos" is set to 0.
- On line 564, since the format argument is "*",
  variable "arg" is set to -1.
- On line 601, variable "size" is set to the same value
  as "arg", so "size" is now -1.
- On line 832, "size" is added to "inputpos", so
  "inputpos" decreases by one and is now -1.
- On line 833, if "inputpos" is < 0 (which it is) an
  error is shown. This error display is one of the
  changes between PHP 4.3.9 and 5.0.3. This error
  display would seem to be what we're seeing in this
  case.

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

[2005-01-10 05:07:06] php-bug-31247 at ryandesign dot com

Description:
------------
I am experiencing the problem reported in bug 31247, 
which was marked as bogus. The decision was that the 
user's compiler was broken. I challenge this decision, 
as I see the problem with the (php.net-endorsed) 
precompiled Mac OS X version of PHP 5.0.3 (release 1) 
from www.entropy.ch and also with PHP 4.3.10 installed 
on a Gentoo server. I don't think all of these 
compilers are broken. I don't see the problem with 
Entropy PHP 4.3.9 (release 2) nor with 4.3.9 on a 
different Gentoo server.

I wonder whether the problem really relates to the 
break-statement-within-the-braces notation, because this 
notation is already present in PHP 4.3.9 which does not 
exhibit the problem. Regardless, I consider braces 
around cases within a switch to be poor form, and 
encourage developers I work with to not use it, as it 
gives the false impression to the uninitiated (which is 
often the person writing the code) that closing the 
brace closes the case (which of course it doesn't; the 
break actually does that).

Reproduce code:
---------------
php -r "print_r(unpack('H*hex', 'data'));"

Expected result:
----------------
Array
(
    [hex] => 64617461
)

Actual result:
--------------
Warning: unpack(): Type H: outside of string in Command 
line code on line 1
Array
(
    [hex] => 64617461
)


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


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

Reply via email to