Does PHP support a "USE BYTES" pragma?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thna_brianb
Forum Newbie
Posts: 6
Joined: Thu Nov 21, 2002 12:24 pm
Contact:

Does PHP support a "USE BYTES" pragma?

Post 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?
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
thna_brianb
Forum Newbie
Posts: 6
Joined: Thu Nov 21, 2002 12:24 pm
Contact:

Best I can

Post 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
thna_brianb
Forum Newbie
Posts: 6
Joined: Thu Nov 21, 2002 12:24 pm
Contact:

Post 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!
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

i also tried searching, but with no results. my guess would be that PHP does not support this kind of functionality.
Post Reply