PHP:Return 带有 NuSoap WebService 的自定义对象数组

PHP: Return Array of Custom Objects with NuSoap WebService

我在 PHP 中创建了以下自定义 class:

<?php

class myClass
{
   public $property1;
   public $property2;
}
?>

我有一个 NuSoap Web 服务,我想将其用于 return 这些对象的数组 XML 格式。我已经为 return 数据构建了以下函数:

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

当我使用 运行 方法时,出现以下错误:

Object of class MyClass could not be converted to string

如有任何帮助,我们将不胜感激!提前致谢。

对象创建错误。

$returnObject = new $myClass;

将上面一行改为下面

$returnObject = new myClass();

这个 post 最终成为我的解决方案:

Notice Array to string conversion using nusoap

显然,当您使用复杂数据类型时,调试转换会中断。幸运的是,第 6132 行可以在 NuSoap.php 中被注释掉而不会导致任何问题。