Page 1 of 1

Does PHP support a "USE BYTES" pragma?

Posted: Thu Nov 21, 2002 12:24 pm
by thna_brianb
I am writing a PHP interface with an API that requires a "Byte Array" as a data type. I know Perl has a "USE BYTES" option that will allow the data to be recognized as bytes. Does anyone know if PHP has similar support for the issue?

Posted: Thu Nov 21, 2002 1:29 pm
by BDKR
Wow. This is a tough one. I couldn't find a thing about it. Could you give an explanation of what a byte-array is. I have an idea as the VB guy here makes mention of it from time to time. However, using primarily dynamically typed scripting languages has probably spoiled me.

Cheers,
BDKR

Best I can

Posted: Thu Nov 21, 2002 1:44 pm
by thna_brianb
This is the best info I can give ...

I am using PEAR SOAP to interface with the API. One of the arguments the API recieves is a "Byte Array" of a CSV file i.e. a CSV file broken up into bytes each byte being an element of an array. Here is the PHP code I used in attempting to create this senario:

<?
$fp = fopen($csv_filename,"rb");
$i = 0;
while(!feof($fp)) {
$byte_array[$i] = fread($fp,1);
$i++;
}
fclose($fp);
?>

When the API result returns, it gives an error in the array type. However a PERL API request that does work is this:


use bytes;
# The following array is a byte array
@fileContents = SOAP::Data->name('file')->value(@file)->type('base64');



Now the obvious answer is to use perl for this application, but it is tied into a larger php appicaton. But as a last resort I can "cludge" the process up with a system or exec call to the perl.

Any help you can provide would be greatly appreciated.

Brian
Seinor Appications Programmer
Tweve Horses North America

Posted: Thu Nov 21, 2002 1:56 pm
by thna_brianb
One more bit of info ... here is the soap request that fails:

<file xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:string[66]" SOAP-ENC:offset="[0]">^M
<item xsi:type="xsd:string">B</item>^M
<item xsi:type="xsd:string">r</item>^M
<item xsi:type="xsd:string">i</item>^M
<item xsi:type="xsd:string">a</item>^M
<item xsi:type="xsd:string">n</item>^M
</item>^M

I can only assume the PEAR SOAP is not sure what element type the array is because PHP is loosely type, so it is interpreting the array elements as strings. Perl has the "use bytes" pragma that will bascially tell what type it is .... Which brings me back to my stumpper ... does PHP have such support.

Thanks All!

Posted: Thu Nov 21, 2002 5:52 pm
by mydimension
i also tried searching, but with no results. my guess would be that PHP does not support this kind of functionality.