Re: [SOAP] Re: A single elemet array turns into an object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Here is a little example, that illustrates how I use arrays:

<?php
require_once 'SOAP/Value.php';
require_once 'SOAP/Server.php';
require_once 'SOAP/Fault.php';

// Base array class
class TArray {
    var $items = array();

    function TArray($values)
    {
        $this->items = $values;
    }
    // returns type of the array
    function _gettype() {
        return 'array';
    }
    // returns a SOAP_Value of array items
    function soapvalue($value,$key) {
        return $value->__to_soap('item');
    }
    function &__to_soap($name)
    {
        $inner = NULL;
        foreach($this->items as $key => $value) {
            $inner[] = $this->soapvalue($value,$key);
        }
        return new SOAP_Value($name, $this->_gettype(), $inner);
    }
}

// Array of Integer
class TIntArray extends TArray {
    function _gettype() {
        return NAMESPACE.'TIntArray';
    }
    function soapvalue($value,$key) {
        return new SOAP_Value('item','int',$value);
    }
}

// my test soap server
class Test {
    function GetArray()
    {
        $array = array(1,2,3,4,5,6);
        $tarray = & new TIntArray($array);
        return $tarray->__to_soap('result');
    }
}

$server = new SOAP_Server;
$server->_auto_translation = true;
$test = new Test();
$server->addObjectMap($test,'urn:myns');
$server->service($HTTP_RAW_POST_DATA);
?>

Roman.

"Mike Carter" <mikeatwork@ukonline.co.uk>
> Hi,
>
> What and where is this special Tarray class?
>
> Regards,
>
> Mike c.
>
> > -----Original Message-----
> > From: Roman Romanov [mailto:nicodim@mail.ru]
> > Sent: 10 September 2003 21:34
> > To: soap@lists.php.net
> > Subject: [SOAP] Re: A single elemet array turns into an object
> >
> >
> > Hi
> >
> > With 0.8RC1 I have not  such problem any more.
> > I use special TArray class for manipulating arrays in my SOAP servers.
> >
> > Roman.
> >
> > "Mike Carter"
> > > Hi,
> > >
> > > I've noticed some strange behaviour with arrays and the SOAP.  Its
> > > always been like this, I've just not had time to report it.
> > >
> > > When PEAR SOAP client recieves an array which has just one
> > element in
> > > it
> > > - it gets converted to a stdClass.  If more than one element in the
> > > array then I get an array.
> > >
> > > Currently this means I must first do a is_array() check on
> > the result
> > > before passing it through something like a foreach() loop.
> > >
> > > Is there a way to prevent such a strange behaviour?  I'm
> > guessing it
> > > has something to do with the automatic type conversion process in
> > > PEAR::SOAP ?
> > >
> > > Regards,
> > >
> > >
> > >
> > > Mike C
> > >
> > >
> > >
> > ______________________________________________________________________
> > > __
> > > This email has been scanned for all viruses by the MessageLabs Email
> > > Security System. For more information on a proactive email security
> > > service working around the clock, around the globe, visit
> > > http://www.messagelabs.com
> > >
> > ______________________________________________________________
> > __________
> >
> > --
> > PHP Soap Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>
>
> ________________________________________________________________________
> This email has been scanned for all viruses by the MessageLabs Email
> Security System. For more information on a proactive email security
> service working around the clock, around the globe, visit
> http://www.messagelabs.com
> ________________________________________________________________________

-- 
PHP Soap Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Kernel Newbies]     [PHP Database]     [Yosemite]

  Powered by Linux