Bug #1830: Unpack() gives fatal error if not enough data.
| From: | danbeck at scott dot net | Date: | Thu, 22 Jul 1999 16:02:08 +0000 |
| Subject: | Bug #1830: Unpack() gives fatal error if not enough data. | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-8979@lists.php.net to get a copy of this message | ||
From: danbeck@scott.net
Operating system: Linux 2.0.36 (RedHat 5.2)
PHP version: 3.0 Latest CVS (22/07/1999)
PHP Bug Type: Misbehaving function
Bug description: Unpack() gives fatal error if not enough data.
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.