Pack function : a suggestion - allow array as second argument.

php.internals

l0t3k

22 years ago
Scenario : i have an extension which requires an external binary (data) file. Since the extension has to be cross platform, the data file has to be built on the target platform to ensure that there are no endian issues. Therefore, i transform the file into a csv file of byte values, hoping to use Pack at the final stage of the build process to create a platform-endian file. The Problem Pack is written "vararg" style, which works great for a small set of values, but is a pain for larger sets of data. i know its possible to loop through my data and do a per-byte conversion, but my file is currently near 90K. Suggestion: Allow for an array as the second parameter. That way all i need to do is : $new_file = fopen($platform_file, "wb"); $lines = file($big_binary_file); foreach ($lines as $line) { $array_of_bytes_as_string = split(",", $line); $bin_string = pack("C*", $array_of_bytes_as_string); fwrite($new_file, $bin_string); } fclose($new_file); In Case You're Wondering: Why am i not doing this via C ? it is quite possible for parts of the total data set to change between releases of the extension. the file i want to convert is fairly static, but there are other data files which the extension user may customize, or that may need to be corrected. in that case, a simple PHP script can be run to create the binary file. No compiler or PHP build environment is necessary, and there is no need to wait for a new release of the extension. l0t3k

Derick Rethans

22 years ago
On Sun, 13 Jun 2004, l0t3k wrote:
> Suggestion: > Allow for an array as the second parameter. That way all i need to do is :
Why not use call_user_func_array? See: http://no2.php.net/call_user_func_array regards, Derick

l0t3k

22 years ago
thanks, i hadn't noticed that. still in the interest of efficiency i think an array should be allowed. or am i the only one having to use Pack on large sets of data ? "Derick Rethans" <derick@php.net> wrote in message news:Pine.LNX.4.58.0406131526340.2284@localhost...

Derick Rethans

22 years ago
On Sun, 13 Jun 2004, l0t3k wrote:
> thanks, i hadn't noticed that. still in the interest of efficiency i think > an array should be allowed. or am i the only one having to use Pack on large > sets of data ?
The problem with if we're going that way, this same argument might hold for all other PHP functions; I think it's not a good idea to start implementing this functionality in PHP functions in general while a perfectly working method with call_user_func_array works too. The performance impact is most likely to be very small too. Derick