function __construct( $data, $type = false )
$type = $this->calculateType();
// Turn all the values in the array in to new IXR_Value objects
foreach ($this->data as $key => $value) {
$this->data[$key] = new IXR_Value($value);
for ($i = 0, $j = count($this->data); $i < $j; $i++) {
$this->data[$i] = new IXR_Value($this->data[$i]);
public function IXR_Value( $data, $type = false ) {
self::__construct( $data, $type );
if ($this->data === true || $this->data === false) {
if (is_integer($this->data)) {
if (is_double($this->data)) {
// Deal with IXR object types base64 and date
if (is_object($this->data) && is_a($this->data, 'IXR_Date')) {
if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) {
// If it is a normal PHP object convert it in to a struct
if (is_object($this->data)) {
$this->data = get_object_vars($this->data);
if (!is_array($this->data)) {
// We have an array - is it an array or a struct?
if ($this->isStruct($this->data)) {
// Return XML for this value
return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>';
return '<int>'.$this->data.'</int>';
return '<double>'.$this->data.'</double>';
return '<string>'.htmlspecialchars($this->data).'</string>';
$return = '<array><data>'."\n";
foreach ($this->data as $item) {
$return .= ' <value>'.$item->getXml()."</value>\n";
$return .= '</data></array>';
$return = '<struct>'."\n";
foreach ($this->data as $name => $value) {
$name = htmlspecialchars($name);
$return .= " <member><name>$name</name><value>";
$return .= $value->getXml()."</value></member>\n";
return $this->data->getXml();
* Checks whether or not the supplied array is a struct or not
function isStruct($array)
foreach ($array as $key => $value) {
if ((string)$key !== (string)$expected) {