From: ifirla at aegissrl dot it
Operating system: Debian GNU/Linux 3.0
PHP version: 4.3.9
PHP Bug Type: Sockets related
Bug description: fwrite (supposed to be binary safe) sends string regardless
of variable type
Description:
------------
an array holds elements of various types:
ascii|integer|integer|integer|integer
in a foreach loop, sending each element to a socket opened with fsockopen
sends the elements as strings, not as the character type.
gettype within the foreach loop shows that I'm sending dealing with the
correct types:
16:39:54 SENT 'K' of type string
16:39:54 SENT '0' of type integer
16:39:54 SENT '0' of type integer
16:39:54 SENT '65' of type integer
16:39:54 SENT '31' of type integer
fwrite is, according to the documentation, supposed to be binary safe.
I think there's a bug in fwrite that has it send all elements as strings.
Reproduce code:
---------------
function send_back($sock, $msg, $ip, $port) {
$fp = fsockopen("udp://$ip", "$port");
foreach ($msg as $msg_to_send) {
fwrite($fp, $msg_to_send);
echo date("H:i:s")." SENT '$msg_to_send' of type
".gettype($msg_to_send)." \n"; //seen server side
}
fclose($fp);
}
Expected result:
----------------
running a packet sniffer, I can see that what's being sent are strings:
15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP |
0000: 4b K
15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP |
0000: 30 0
15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP |
0000: 30 0
15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP |
0000: 3635 65
15:46:10 192.168.0.101:32778 --> 192.168.0.84:32896 | UDP |
0000: 3331 31
Actual result:
--------------
Those last two (65 and 31) should be represented by single bytes, not two
bytes.
--
Edit bug report at http://bugs.php.net/?id=31090&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31090&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=31090&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=31090&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31090&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31090&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31090&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31090&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31090&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31090&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31090&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=31090&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=31090&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31090&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31090&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31090&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31090&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31090&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31090&r=float
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31090&r=mysqlcfg