auto-translation: class default values clash

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

 



Hi,

just to report something that I noticed using PEAR::SOAP type auto
translation. DO NOT to assign default values (other than NULL) to any
variable in the target PHP class because, if you do, actual values coming
from the SOAP wire will be combined with the default values into an array of
two values.

E.g.: suppose that some user class is defined for receiving the SOAP result
of a SOAP server, like this:

    class MyPerson {
        var $Name = null;     // string
        var $Age = null;        // integer
    };

and an AutoTranslation is defined between an XML Type and this PHP class:

    ...
    $client->_auto_translation = true;
    $client->__set_type_translation('{urn:MyNamespace}PersonType',
'myperson');

This is fine and works as expected: that is, if the concerned chunk of the
XML message is:

<Person xsi:type="ns4:PersonType'">
  <Name xsi:type="xsd:string">John Doe</Name>
  <Age xsi:type="xsd:positiveInteger">44</Age>
</Person>

then the var_dump of the converted object will look like this:

object(myperson)(2) {
  ["Name"]=>
  string(8) "John Doe"
  ["Age"]=>
  int(44)
}

BUT: if you assign default values to the class members, such as:

    class MyPerson {
        var $Name = "(unspecified)";     // string
        var $Age = 0;        // integer
    };

you'll get a result which is messed-up with the default values:

object(myperson)(2) {
  ["Name"]=>
  array(2) {
    [0]=>
    string(13) "(unspecified)"
    [1]=>
    string(8) "John Doe"
  }
  ["Age"]=>
  array(2) {
    [0]=>
    int(0)
    [1]=>
    int(44)
  }
}

Coming to the "why" part: It seems that PEAR::SOAP doesn't want to overwrite
any existing values so if it finds another value in the place where the new
value must to be stored (other than NULL) then it converts the thing into an
array and appends the new value there. There is a point here (XMLs
cointaining multiple elements with the same name, without actually being
into a SOAP-ENC:Array), but for common usage it is a weird behaviour and
perhaps there should be a way to get rid of it.

Bye
Michele

-- 
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