[英]PHP: Return Array of Custom Objects with NuSoap WebService
I have created the following custom class in PHP: 我在PHP中创建了以下自定义类:
<?php
class myClass
{
public $property1;
public $property2;
}
?>
I have a NuSoap Webservice that I want to use to return an array of these objects in XML format. 我有一个NuSoap Web服务,我想使用它以XML格式返回这些对象的数组。 I have built the following function to return the data:
我建立了以下函数来返回数据:
foreach($response->return->object as $object)
{
$returnObject = new $myClass;
$returnObject->property1 = $object->property1;
$returnObject->property2 = $object->property2;
array_push($returnObjects, $returnObject);
}
}
$result = array_unique($returnObjects);
if (count($result) != 0){
return $result;}
When I run the method, I get the following error: 运行该方法时,出现以下错误:
Object of class MyClass could not be converted to string
MyClass类的对象无法转换为字符串
Any assistance would be greatly appreciated! 任何帮助将不胜感激! Thanks in advance.
提前致谢。
Object creation is wrong. 对象创建是错误的。
$returnObject = new $myClass;
change above line to following 将上面的行更改为以下行
$returnObject = new myClass();
This post ended up being my solution: 这篇文章最终成为我的解决方案:
Notice Array to string conversion using nusoap 注意使用nusoap进行数组到字符串的转换
Evidently there is a debugging conversion that breaks when you use complex data types. 显然,当您使用复杂的数据类型时,调试转换会中断。 Luckily line 6132 can be commented out in the NuSoap.php without causing any issues.
幸运的是,可以在NuSoap.php中注释掉6132行,而不会引起任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.