PHP 4.0 Bug #1830 Updated: Unpack() gives fatal error if not enough data.
| From: | jimw@php.net | Date: | Sat, 10 Feb 2001 18:38:16 +0000 |
| Subject: | PHP 4.0 Bug #1830 Updated: Unpack() gives fatal error if not enough data. | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-46190@lists.php.net to get a copy of this message | ||
ID: 1830
Updated by: jimw
Reported By: danbeck@scott.net
Status: Open
Bug Type: Feature/Change Request
Assigned To:
Comments:
refiled against 4.0.
Previous Comments:
---------------------------------------------------------------------------
[1999-11-11 19:12:39] joey@cvs.php.net
While I agree that this is undesirable behavior,
I am moving this to a feature request, rather than
a misbehaving function, as the intended behavior
is correctly taking place.
---------------------------------------------------------------------------
[1999-07-22 12:02:08] danbeck@scott.net
Unpack dies with a fatal error if the length of the data does not match the length of the template
supplied.
I know that this was intended, but it's sort of harsh, don't you think? If you were
relying on data from an external source, how would you handle bad data so that your scripts could
continue working? The only way I see here is to actually check the data to make sure it's the
length of the template. But this is error prone because if you ever changed your template setup,
you would need to update your minimum data size.
I think the perl way is *much* better. If perl doesn't have enough data for the template, if
fills out as many elements as it can and the rest of the array would be empty. That way your script
doesn't die in the middle of execution, it just doesn't return quite as much data as you
expected.
If I had a choice between displaying this to a user:
Fatal error: pack type A: not enough input, need 10, have 4 in /home/httpd/html/rpt/btrieve.phtml on
line 496
or allowing me to check for missing elements in the array and responding appropriately, I prefer the
latter.
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=1830&edit=2