how can i pack an object in php and send it over udp? i have a packet class that has 6 propertis :
/** @var 32int */
private $headerSize;
/** @var 32int */
private $highSessionID;
/** @var 32int */
private $lowSessionID;
/** @var array (char) */
private $signature;
/** @var 32int */
private $comandID;
/** @var 32int */
private $dataSize;
i tried a simple client-server app that it send a string over udp but i want to send an object that have different type of data
Edited : I used pack and serialized function , they were very helpful but i have one more question :
I read manual in php.net but i did not understand how to pack different type of data . i tried this :
$n = ord('a');
$buf = pack('IS',200000000,$n);
$array = unpack('I/S', $buf);
foreach ($array as $key => $value)
echo "\$array[$key] = ". $value ."<br>\n";
output :
$array[1] = 97<br>
why 200000000 was not print ? how can i fix the code?
thx.
I found my mistake:
The unpacked data is stored in an associative array. To accomplish this you have to name the different format codes and separate them by a slash /. If a repeater argument is present, then each of the array keys will have a sequence number behind the given name.