|
wddx_serialize_vars
Serialize variables into a WDDX packet
(PHP 4, PHP 5)
Example 2614. wddx_serialize_vars() example<?php The above example will output: <wddxPacket version='1.0'><header/><data><struct><var name='a'><number>1</number></var> Code Examples / Notes » wddx_serialize_varstychay
You can use globals to get around the above in classes: <?php class Test { var $str; var $wddx; function Test() { $this->str = "test"; $this->wddx_serialize($this->str); header('Content-Type: text/xml'); echo ($this->wddx); } function wddx_serialize($var) { global $wddxtemp; unset($wddxtemp); $wddxtemp = $var; $this->wddx = wddx_serialize_vars("wddxtemp"); } } new Test(); ?> -terry christian dot knoflach
Be careful using WDDX - functions on object variables. As I just had to find out the following won't work: <?php class Test { var $str; var $wddx; function Test() { $this->str = "test"; $this->wddx = wddx_serialize_vars("this->str"); print(htmlentities($this->wddx)); } } new Test(); ?> That's what you'll get: <wddxPacket version='1.0'><header/><data><struct></struct></data></wddxPacket> kangus
A function to use for dates with PHP & WDDX getdate() $ta="<FORM><TEXTAREA rows=15 cols=80>" ; $te="</TEXTAREA></FORM>"; $packet_id=wddx_packet_start("Date Example--"); $myDate=getdate(); wddx_add_vars($packet_id,'myDate'); $package=wddx_packet_end($packet_id); print($ta.$package.$te); Produces: <wddxPacket version='1.0'><header><comment>Date Example--</comment></header> <data><struct><var name='myDate'> <struct><var name='seconds'><number>12</number></var> <var name='minutes'><number>55</number></var> <var name='hours'><number>1</number></var> <var name='mday'><number>13</number></var> <var name='wday'><number>1</number></var> <var name='mon'><number>10</number></var> <var name='year'><number>2003</number></var> <var name='yday'><number>285</number></var> <var name='weekday'><string>Monday</string></var> <var name='month'><string>October</string></var> <var name='0'><number>1066031712</number> </var></struct></var></struct></data></wddxPacket> |