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.

2 Answers 2

0

Object creation is wrong.

$returnObject = new $myClass;

change above line to following

$returnObject = new myClass();
Sign up to request clarification or add additional context in comments.

1 Comment

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.