#5889 [Ana->WFx]: pack() does not take arrays
| From: | magnus@php.net | Date: | Mon, 14 Jun 2004 08:49:21 +0000 |
| Subject: | #5889 [Ana->WFx]: pack() does not take arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-60864@lists.php.net to get a copy of this message | ||
ID: 5889
Updated by: magnus@php.net
Reported By: tomwk at audiogalaxy dot com
-Status: Analyzed
+Status: Wont fix
Bug Type: Feature/Change Request
Operating System: Redhat Linux
PHP Version: 4.0.1pl2
New Comment:
This will not be implemented.
Previous Comments:
------------------------------------------------------------------------
[2000-08-01 10:22:25] stas@php.net
Well, functions args work differently in perl and PHP. Maybe we need
some "array" type of pack modifier, because PHP does not convert
function arguments to array. Though, you can write a wrapper function
using func_get_args() and func_num_args() for this.
------------------------------------------------------------------------
[2000-08-01 09:51:18] tomwk at audiogalaxy dot com
I have an application that writes data across our network
to another program. Most of the data consists of integer arrays. I'm
currently doing this in a very simple manner,
using something like this:
for( $i = 0; $i < $numInts; $i++ ) {
fwrite( $fd, pack( "N", $ints[ $i ] ) );
}
However, this results in a very large number of calls to
fwrite, which is bad for performance. I made the routine
about 3 times faster by doing something like this:
fwrite( $fd, pack( "N10"
$ints[ $i + 0 ],
$ints[ $i + 1 ],
$ints[ $i + 2 ], ///.. and so on,
However, it would be really great if pack could take an array as one of
it's arguments. I believe this is the way
Perl behaves, but when I try:
$data = array( 10, 123 );
$buf = pack( "N*", $data );
$valArray = unpack( "N*", $buf );
while( list( $key, $val ) = each( $valArray ) ) {
echo "$key -> $val\n";
}
the only output I get is:
1 -> 1
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=5889&edit=1