wddx_serialize_vars

(PHP 4, PHP 5, PHP 7)

wddx_serialize_vars変数を WDDX パケットにシリアライズする

警告

この機能は PHP 7.4.0 で 削除 されました。

説明

wddx_serialize_vars(mixed $var_name, mixed ...$var_names): string

指定された変数をシリアライズしたものを含む構造体を用いて WDDX パケットを作成します。

パラメータ

この関数は、可変長のパラメータを受け取ります。

var_name

変数名を表す文字列、あるいは配列。 配列の中身は、変数名を表す文字列あるいは別の配列などとなります。

var_names

戻り値

WDDX パケット、あるいはエラー時に false を返します。

例1 wddx_serialize_vars() の例

<?php
$a
= 1;
$b = 5.5;
$c = array("blue", "orange", "violet");
$d = "colors";

$clvars = array("c", "d");
echo
wddx_serialize_vars("a", "b", $clvars);
?>

上の例の出力は以下となります。

<wddxPacket version='1.0'><header/><data><struct><var name='a'><number>1</number></var>
<var name='b'><number>5.5</number></var><var name='c'><array length='3'>
<string>blue</string><string>orange</string><string>violet</string></array></var>
<var name='d'><string>colors</string></var></struct></data></wddxPacket>

add a note add a note

User Contributed Notes 5 notes

up
2
kangus at jaga dot us
21 years ago
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>
up
2
tychay at alumni dot caltech dot edu
22 years ago
The above feature will cause a slight trouble since the name of the variable will always be "wddxtemp" but you can use preg_replace to fix that.

Also, a better approach is to serialize the entire class. WDDX will that write a reserved "php_class_name" variable which can be used to reconstruct the class during a deserialize.
up
2
tychay at alumni dot caltech dot edu
22 years ago
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
up
0
tychay at alumni dot caltech dot edu
22 years ago
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
up
0
christian dot knoflach at gmx dot at
23 years ago
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>
To Top