0

I have created the following custom class in 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. 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

Any assistance would be greatly appreciated! Thanks in advance.

GED125
  • 476
  • 4
  • 18

2 Answers2

0

Object creation is wrong.

$returnObject = new $myClass;

change above line to following

$returnObject = new myClass();
Paresh Gami
  • 4,777
  • 5
  • 23
  • 41
  • In the process of obfuscation this was a type-o. I actually had "new myClass" without the dollar sign. I changed it to your suggestion and there was no change in the result. – GED125 Mar 20 '16 at 18:45
0

This post ended up being my solution:

Notice Array to string conversion using 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.

Community
  • 1
  • 1
GED125
  • 476
  • 4
  • 18