Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg

PHP : Function Reference : WDDX Functions

WDDX Functions


These functions are intended for work with » WDDX.


In order to use WDDX, you will need to install the expat library (which comes with Apache 1.3.7 or higher).


After installing expat compile PHP with --enable-wddx.

The windows version of PHP has built in support for this extension. You do not need to load any additional extension in order to use these functions.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

This extension defines a WDDX packet identifier returned by wddx_packet_start().

Predefined Constants

This extension has no constants defined.


All the functions that serialize variables use the first element of an array to determine whether the array is to be serialized into an array or structure. If the first element has string key, then it is serialized into a structure, otherwise, into an array.

Example 2612. Serializing a single value with WDDX

echo wddx_serialize_value("PHP to WDDX packet example", "PHP packet");

This example will produce:

<wddxPacket version='1.0'><header comment='PHP packet'/><data>
<string>PHP to WDDX packet example</string></data></wddxPacket>

Example 2613. Using incremental packets with WDDX

= 3.1415926;
$packet_id = wddx_packet_start("PHP");
wddx_add_vars($packet_id, "pi");

/* Suppose $cities came from database */
$cities = array("Austin", "Novato", "Seattle");
wddx_add_vars($packet_id, "cities");

$packet = wddx_packet_end($packet_id);

This example will produce:

<wddxPacket version='1.0'><header comment='PHP'/><data><struct>
<var name='pi'><number>3.1415926</number></var><var name='cities'>
<array length='3'><string>Austin</string><string>Novato</string>


If you want to serialize non-ASCII characters you have to convert your data to UTF-8 first (see utf8_encode() and iconv()).

Table of Contents

wddx_add_vars — Add variables to a WDDX packet with the specified ID
wddx_deserialize — Alias of wddx_unserialize()
wddx_packet_end — Ends a WDDX packet with the specified ID
wddx_packet_start — Starts a new WDDX packet with structure inside it
wddx_serialize_value — Serialize a single value into a WDDX packet
wddx_serialize_vars — Serialize variables into a WDDX packet
wddx_unserialize — Unserializes a WDDX packet

Code Examples / Notes » ref.wddx


With ref to the above comment about typing, I have found that -- oddly enough -- PHP's WDDX supports the following WDDX types: null, boolean (true/false), number and string, *but* not date-time.
as an example, use the following values in an array that you then serialize:
$number = 5,
$null = NULL,
$bool = true,
$string = 'this is a string'.
they will all serialize correctly, e.g. the third entry comes out as:
<var name='bool'><boolean value='true'/></var>
i have tried with the 'official' format for WDDX 'datetime', e.g. '1998-9-15T09:05:32+4:0' (from the DTD @  but have only succeeded in getting this encoded as a 'string' type.
if anyone else has any more information on this, it would be welcome. i would like to store the variables in 'appropriate' fields in a database, and the fact that only datetime is not supported is slightly irritating -- otherwise it would be a very useful function.

12-sep-2003 03:29

wddx isn't 100% perl compatible .. I have an wddx file infront of me and it only works with php so better don't use it


Tutorial here :
XML and PHP. Part 1: Using the WDDX functions


To insert arrays into a wddx variable here is a fine way to do it:
$sql = 'SELECT * FROM example';
$query = mysql_query($sql, $db) or die(mysql_error());
while($result = mysql_fetch_array($query)) {
$id[] = $result[ 'id'];
$name[] = $result['name'];
$description[] = $result[$prefix . 'description'];
wddx_add_vars($packet_id, "id");
wddx_add_vars($packet_id, "name");
wddx_add_vars($packet_id, "description");
$wddxSerializeValue = wddx_packet_end($packet_id);


To bradburn at kiwi dot de:
PHP is only capable of serializing properly variables which match one of its native (scalar) types (See Which means that only variables of type booleans, integers, floating point numbers, string and NULL will be serialized properly.
I think there are two exceptions though:
- arrays are serialized by processing them recursively, so if its only composed of the above mentioned types, you should be fine.
- floating point numbers and integers may use the same representation while serialized in WDDX (I don't know much about WDDX, so I'm not 100% sure about this statement).
An interesting case would be whether objects can be serialized or not...


Since there aren't any examples of reversing the process, here's one. If you had the packet produced by the above example (without the htmlentities() call), you could retrieve the values like this:
$value = wddx_deserialize($packet);
print "pi is:
" . $value["pi"] . "

print "cities is:
while (list($key, $val) = each($value["cities"])) {
print "$key => $val
which outputs:
pi is:
cities is:
0 => Austin
1 => Novato
2 => Seattle

jimmy wimenta

PHP's WDDX is useful only for exchanging data between PHP applications, but definetly not for exchanging data between different languages (which actually defeats the purpose of WDDX).
For example:
$hash1 = array ("2" => "Two", "4" => "Four", "5" => "Five");
$hash2 = array ("0" => "Zero", "1" => "One", "2" => "Two");
$hash1 will be serialized as hash, but
$hash2 will be serialized as array/list, because the key happen to be a sequence starting from 0.
Unless the library provide a way for users to specify the type, it can never be used for cross-platform data exchange.


I think it would be helpful for passing data between languages to show a direct translation of the above examples into Perl, using 1.00 from CPAN.  It took me awhile to figure out.  To serialize:
use WDDX;
$wddx = new WDDX;
$packet_id = $wddx->struct({});
$pi = 3.1415926;
$packet_id->set("pi" => $wddx->number($pi));
# Suppose @cities came from database
@cities = ("Austin", "Novato", "Seattle");
$packet_id->set("cities" => $wddx->array([map $wddx->string($_), @cities]));
$packet = $wddx->serialize($packet_id);
open(FP, ">cities.wddx");
print FP $packet;

To deserialize:
use WDDX;
open(FP, "<cities.wddx");
undef $/;                       # Slurp the whole file.
$packet = <FP>;
$packet_id = new WDDX;
$wddx_obj = $packet_id->deserialize($packet);
$value = $wddx_obj->as_hashref();
print "pi is:
" . $value->{"pi"} . "

print "cities is:
$key = 0;
foreach $val (@{$value->{"cities"}}) {
   print "$key => $val
</PRE>, sbarnum

Change Language

Follow Navioo On Twitter
.NET Functions
Apache-specific Functions
Alternative PHP Cache
Advanced PHP debugger
Array Functions
Aspell functions [deprecated]
BBCode Functions
BCMath Arbitrary Precision Mathematics Functions
PHP bytecode Compiler
Bzip2 Compression Functions
Calendar Functions
CCVS API Functions [deprecated]
Class/Object Functions
Classkit Functions
ClibPDF Functions [deprecated]
COM and .Net (Windows)
Crack Functions
Character Type Functions
Cybercash Payment Functions
Credit Mutuel CyberMUT functions
Cyrus IMAP administration Functions
Date and Time Functions
DB++ Functions
Database (dbm-style) Abstraction Layer Functions
dBase Functions
DBM Functions [deprecated]
dbx Functions
Direct IO Functions
Directory Functions
DOM Functions
DOM XML Functions
enchant Functions
Error Handling and Logging Functions
Exif Functions
Expect Functions
File Alteration Monitor Functions
Forms Data Format Functions
Fileinfo Functions
filePro Functions
Filesystem Functions
Filter Functions
Firebird/InterBase Functions
Firebird/Interbase Functions (PDO_FIREBIRD)
FriBiDi Functions
FrontBase Functions
FTP Functions
Function Handling Functions
GeoIP Functions
Gettext Functions
GMP Functions
gnupg Functions
Haru PDF Functions
hash Functions
Hyperwave Functions
Hyperwave API Functions
i18n Functions
IBM Functions (PDO_IBM)
iconv Functions
ID3 Functions
IIS Administration Functions
Image Functions
Imagick Image Library
Informix Functions
Informix Functions (PDO_INFORMIX)
Ingres II Functions
IRC Gateway Functions
PHP / Java Integration
JSON Functions
LDAP Functions
libxml Functions
Lotus Notes Functions
LZF Functions
Mail Functions
Mailparse Functions
Mathematical Functions
MaxDB PHP Extension
MCAL Functions
Mcrypt Encryption Functions
MCVE (Monetra) Payment Functions
Memcache Functions
Mhash Functions
Mimetype Functions
Ming functions for Flash
Miscellaneous Functions
mnoGoSearch Functions
Microsoft SQL Server Functions
Microsoft SQL Server and Sybase Functions (PDO_DBLIB)
Mohawk Software Session Handler Functions
mSQL Functions
Multibyte String Functions
muscat Functions
MySQL Functions
MySQL Functions (PDO_MYSQL)
MySQL Improved Extension
Ncurses Terminal Screen Control Functions
Network Functions
Newt Functions
NSAPI-specific Functions
Object Aggregation/Composition Functions
Object property and method call overloading
Oracle Functions
ODBC Functions (Unified)
ODBC and DB2 Functions (PDO_ODBC)
OpenAL Audio Bindings
OpenSSL Functions
Oracle Functions [deprecated]
Oracle Functions (PDO_OCI)
Output Control Functions
Ovrimos SQL Functions
Paradox File Access
Parsekit Functions
Process Control Functions
Regular Expression Functions (Perl-Compatible)
PDF Functions
PDO Functions
Phar archive stream and classes
PHP Options&Information
POSIX Functions
Regular Expression Functions (POSIX Extended)
PostgreSQL Functions
PostgreSQL Functions (PDO_PGSQL)
Printer Functions
Program Execution Functions
PostScript document creation
Pspell Functions
qtdom Functions
Rar Functions
GNU Readline
GNU Recode Functions
RPM Header Reading Functions
runkit Functions
SAM - Simple Asynchronous Messaging
Satellite CORBA client extension [deprecated]
SCA Functions
SDO Functions
SDO XML Data Access Service Functions
SDO Relational Data Access Service Functions
SESAM Database Functions
PostgreSQL Session Save Handler
Session Handling Functions
Shared Memory Functions
SimpleXML functions
SNMP Functions
SOAP Functions
Socket Functions
Standard PHP Library (SPL) Functions
SQLite Functions
SQLite Functions (PDO_SQLITE)
Secure Shell2 Functions
Statistics Functions
Stream Functions
String Functions
Subversion Functions
Shockwave Flash Functions
Swish Functions
Sybase Functions
TCP Wrappers Functions
Tidy Functions
Tokenizer Functions
Unicode Functions
URL Functions
Variable Handling Functions
Verisign Payflow Pro Functions
vpopmail Functions
W32api Functions
WDDX Functions
win32ps Functions
win32service Functions
xattr Functions
xdiff Functions
XML Parser Functions
XML-RPC Functions
XMLReader functions
XMLWriter Functions
XSL functions
XSLT Functions
YAZ Functions
YP/NIS Functions
Zip File Functions
Zlib Compression Functions
eXTReMe Tracker