First: this isn't a result issue, it's a request issue, so outgoing XML from
the server is meaningless. It's the request coming from PHP to service that
is sending up empty strings instead of null.
Second: I didn't say null is a String. What I said was empty strings are not
null. Every language I've used allows null to be bound to any type.
List<Category> getCategories(String parentId, String
functionId){return null;}
Can most certainly be called as
getCategories(null, "asdf");
And is being done so from both .Net and Flex-based consumers of the service.
After some more research, I found this actually isn't only a PHP/Java issue.
It seems there's no official way of dealing with nulls as values through
SOAP, so different platforms deal with it differently. There is a widely
adopted solution to using xsi:nil instead. PHP's SoapClient actually
supported this as of 5.1.6, but in 5.2.x it's not working.
http://code.google.com/support/bin/answer.py?answer=64736&topic=10048
So, to restore this functionality, we came up with this (if any of you are
interested):
<?php
class XSoapClient extends SoapClient
{
const SOAP_ENV_NS = "http://schemas.xmlsoap.org/soap/envelope/";
const XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
const _NULL_ = "xxx_replacedduetobrokephpsoapclient_xxx";
protected $mustParseNulls = false;
public function __doRequest($request, $location, $action, $version,
$one_way = null)
{
if($this->mustParseNulls)
{
$this->mustParseNulls = false;
$request =
preg_replace('/<ns1:(\w+)>'.self::_NULL_.'<\/ns1:\\1>/',
'<ns1:$1 xsi:nil="true"/>',
$request, -1, &$count);
if ($count > 0)
{
$request = preg_replace('/(<SOAP-ENV:Envelope )/',
'\\1
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ',
$request);
}
}
return parent::__doRequest($request, $location, $action,
$version, $one_way);
}
public function __call($method, $params)
{
foreach($params as $k => $v)
{
if($v === null)
{
$this->mustParseNulls = true;
$params[$k] = self::_NULL_;
}
}
return parent::__call($method, $params);
}
}
?>
-----Original Message-----
From: Scott Mattocks [mailto:[EMAIL PROTECTED]
Sent: Wednesday, October 22, 2008 12:08 PM
To: Beau Scott
Cc: 'PHP List'
Subject: Re: [UPHPU] SoapClient woes
Beau Scott wrote:
> ("" === NULL) = false. Even PHP knows that.
The problem is that Java is expecting a string and you are sending NULL.
NULL is not a string. Not in any language. With Java if you tell it to
expect a string, it expects a string and nothing else will do. If you
tell it to expect a string or null (with nil="true") it will be smart
enough to handle the value correctly.
> I don't think this isn't a strongly-typed vs loosely-typed issue, this is
an
> issue of SoapClient transforming NULL to an empty string rather than
> following the soap standard and setting the xsi:nil attribute to true as
it
> should when building the SOAP vars out.
Java is pickier than most. We had people build all sorts of clients for
our API and never had a problem until someone tried building a Java
client. PHP and .NET never had problems.
Are you able to capture your outgoing XML from the server and see what
it looks like? Make sure the XML you are sending back matches the WSDL.
_______________________________________________
UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net