note 36117 deleted from ref.wddx by didou

From: Date: Sat, 03 Feb 2007 16:18:47 +0000
Subject: note 36117 deleted from ref.wddx by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-122676@lists.php.net to get a copy of this message
Note Submitter: pierre dot jeunejean at adnexus dot be ---- This is, to me, a nice way to solve the date problem. In this example, we use a custom Date Object to store a date. We show the serialized value in a textarea. We unserialize the packet and then we loop trough the returned array to get each element value and the data type of each of those values. Here is the code, and after it its ouptut: <?PHP class Date { var $date = null; function Date ($date) { $this->date = $date; } } $textValue = "Per idem tempus annorum."; $numberValue = 23; $booleanValue = true; $null = null; $dateValue = new Date('22/03/2003'); $packet_id = wddx_packet_start(); wddx_add_vars($packet_id, "dateValue"); wddx_add_vars($packet_id, "textValue"); wddx_add_vars($packet_id, "numberValue"); wddx_add_vars($packet_id, "booleanValue"); wddx_add_vars($packet_id, "null"); $wddxSerializeValue = wddx_packet_end($packet_id); echo("<FORM><TEXTAREA rows=15 cols=80>" . $wddxSerializeValue . "</TEXTAREA></FORM>"); $wddxDeserialize = wddx_deserialize($wddxSerializeValue); foreach ($wddxDeserialize as $key => $value) { if(is_object($value)) { //checks if the value is an object $valueType = get_class($value); //gets the NAME of the class, so the type of the current value $value = $value->date; //gets the value of the date property of the current Date Object } else { $valueType = gettype($value); } echo("Value = " . $value . "&nbsp;&nbsp;&nbsp;(Value type = " . $valueType . ")<br>"); } ?> <wddxPacket version='1.0'> <header/> <data><struct> <var name='dateValue'><struct> <var name='php_class_name'><string>date</string></var> <var name='date'><string>22/03/2003</string></var> </struct></var> <var name='textValue'><string>Per idem tempus annorum.</string></var> <var name='numberValue'><number>23</number></var> <var name='booleanValue'><boolean value='true'/></var> <var name='null'><null/></var> </struct></data> </wddxPacket> Value = 22/03/2003 (Value type = date) Value = Per idem tempus annorum. (Value type = string) Value = 23 (Value type = integer) Value = 1 (Value type = boolean) Value = (Value type = NULL)

« previous php.notes (#122676) next »