Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8876747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:17:12+00:00 2026-06-14T19:17:12+00:00

I am having problem converting a php Exception to a generic class. I am

  • 0

I am having problem converting a php Exception to a generic class.

I am calling a web service method and when it fails it returns a soap fault with information in the “detail tag”. This is how the result looks like if I call the web service method with Soap UI (http://soapui.org) :

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:Body>
      <s:Fault>
         <faultcode>s:Client</faultcode>
         <faultstring xml:lang="sv-SE">Error Posting New Sponsor Full to Middleware</faultstring>
         <detail>
            <MyPlanWSError xmlns="http://schemas.datacontract.org/2004/07/MyPlanPOA" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
               <BadParameters i:nil="true"/>
               <Details>2 duplicate(s) detected</Details>
               <Duplicates>
                  <DuplicateInfo>
                     <DuplicatedExtRelNo>0</DuplicatedExtRelNo>
                     <POAStatus>New</POAStatus>
                     <Source>NewExtRels</Source>
                     <SourceRecordID>194</SourceRecordID>
                     <Type>eMail</Type>
                  </DuplicateInfo>
                  <DuplicateInfo>
                     <DuplicatedExtRelNo>0</DuplicatedExtRelNo>
                     <POAStatus>New</POAStatus>
                     <Source>NewExtRels</Source>
                     <SourceRecordID>194</SourceRecordID>
                     <Type>Address</Type>
                  </DuplicateInfo>
               </Duplicates>
               <ErrorNumber>7</ErrorNumber>
            </MyPlanWSError>
         </detail>
      </s:Fault>
   </s:Body>
</s:Envelope>

I want to get the MyPlanWSError content that is in the “detail” tag. I want to convert that to a php class.

I have used the nice tool wsdl2php (http://www.urdalen.no/wsdl2php) to generate helper classes based on a wsdl file, so that I don’t have to write all code myself 🙂 The tool generated the MyPlanWSError which looks like this:

class MyPlanWSError
{
  public $BadParameters;
  public $Details;
  public $Duplicates;
  public $ErrorNumber;
  public function __construct($BadParameters, $Details, $Duplicates, $ErrorNumber)
  {
    $this->BadParameters = $BadParameters;
    $this->Details = $Details;
    $this->Duplicates = $Duplicates;
    $this->ErrorNumber = $ErrorNumber;
  }
}

When I call the web service method (that returns the soap fault), I do that in a try catch clause:

function add_new_sponsor() {
  // ... code
  try {
    $new_sponsor = new PostNewSponsor(
        $accessKey,
        $type,
        $initialRecordStatus,
        $monthlyAmount,
        $categoryCode,
        $titleCode,
        $firstName,
        $lastName,
        $organisationName,
        $street,
        $houseNumber,
        $apartment,
        $extraAddressLine,
        $postCode,
        $town,
        $countryISOCode,
        $privatePhone,
        $mobilePhone,
        $workPhone,
        $eMailAddress,
        $sourceCode,
        $paymentFrequencyCode,
        $paymentTypeCode,
        $numberOfChildren,
        $scGender,
        $continentCode,
        $scCountryISOCode,
        $olderChildFlag,
        $personalID,
        $AddressTypeCode,
        $extRelNo,
        $comments,
        $iPAddress);

    $result = plan_utils_post_sponsor($new_sponsor);
  } catch (Exception $e) {
    echo 'Exception->detail var_dump: <br/>';
    var_dump($e->detail);
    echo '<br/></br>';

    $myplan_error = cast('MyPlanWSError', $e->detail);
    echo 'MyPlanWSError var_dump <br/>';
    var_dump($myplan_error);
    echo '<br/><br/>';

    echo 'MyPlanWSError->Details var_dump <br/>';
    var_dump($myplan_error->Details);
    echo '<br/><br/>';
  }
}

function cast($destination, $sourceObject)
{
    if (is_string($destination)) {
        $destination = new $destination();
    }
    $sourceReflection = new ReflectionObject($sourceObject);
    $destinationReflection = new ReflectionObject($destination);
    $sourceProperties = $sourceReflection->getProperties();
    foreach ($sourceProperties as $sourceProperty) {
        $sourceProperty->setAccessible(true);
        $name = $sourceProperty->getName();
        $value = $sourceProperty->getValue($sourceObject);
        if ($destinationReflection->hasProperty($name)) {
            $propDest = $destinationReflection->getProperty($name);
            $propDest->setAccessible(true);
            $propDest->setValue($destination,$value);
        } else {
            $destination->$name = $value;
        }
    }
    return $destination;
}

The cast method was taken from //http://stackoverflow.com/questions/3243900/convert-cast-an-stdclass-object-to-another-class.

So what I expect the output to be from the var_dump($myplan_error->Details) is "2 duplicate(s) detected" but instead I get NULL 🙁

Here is the whole output from the catch clause:

Exception->detail var_dump:
object(stdClass)#4 (1) { ["MyPlanWSError"]=> object(stdClass)#5 (4) { ["BadParameters"]=> NULL ["Details"]=> string(23) "2 duplicate(s) detected" ["Duplicates"]=> object(stdClass)#6 (1) { ["DuplicateInfo"]=> array(2) { [0]=> object(stdClass)#7 (5) { ["DuplicatedExtRelNo"]=> string(1) "0" ["POAStatus"]=> string(3) "New" ["Source"]=> string(10) "NewExtRels" ["SourceRecordID"]=> string(3) "194" ["Type"]=> string(5) "eMail" } [1]=> object(stdClass)#8 (5) { ["DuplicatedExtRelNo"]=> string(1) "0" ["POAStatus"]=> string(3) "New" ["Source"]=> string(10) "NewExtRels" ["SourceRecordID"]=> string(3) "194" ["Type"]=> string(7) "Address" } } } ["ErrorNumber"]=> string(1) "7" } }

MyPlanWSError var_dump
object(MyPlanWSError)#3 (5) { ["BadParameters"]=> NULL ["Details"]=> NULL ["Duplicates"]=> NULL ["ErrorNumber"]=> NULL ["MyPlanWSError"]=> object(stdClass)#5 (4) { ["BadParameters"]=> NULL ["Details"]=> string(23) "2 duplicate(s) detected" ["Duplicates"]=> object(stdClass)#6 (1) { ["DuplicateInfo"]=> array(2) { [0]=> object(stdClass)#7 (5) { ["DuplicatedExtRelNo"]=> string(1) "0" ["POAStatus"]=> string(3) "New" ["Source"]=> string(10) "NewExtRels" ["SourceRecordID"]=> string(3) "194" ["Type"]=> string(5) "eMail" } [1]=> object(stdClass)#8 (5) { ["DuplicatedExtRelNo"]=> string(1) "0" ["POAStatus"]=> string(3) "New" ["Source"]=> string(10) "NewExtRels" ["SourceRecordID"]=> string(3) "194" ["Type"]=> string(7) "Address" } } } ["ErrorNumber"]=> string(1) "7" } }

MyPlanWSError->Details var_dump
NULL

So it seems the problem is that I can’t succeed converting the $e>detail to a MyPlanWSError class.

Any ideas? 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:17:13+00:00Added an answer on June 14, 2026 at 7:17 pm

    Looks like you’re trying to cast the detail object, not the MyPlanWSError object. Thus, its properties aren’t matching up, and the resulting object has all null values.

    Try this instead, and it should work fine:

    $myplan_error = cast('MyPlanWSError', $e->detail->MyPlanWSError);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a problem converting a div to a php variable. This works
I'm having issues connecting to the Magento SOAP API via PHP's SoapClient. I have
I am having problem converting my SQL query to LINQ. How would you create
I'm having a problem with converting some string short time values to a 24
i'm having a problem while converting Timestamp objects to joda's LocalTime. See example below:
I'm having a problem with converting binary strings to signed integers If you call
I'm having a problem where PHP is reporting an open_basedir restriction error when CakePHP
I am having problem while connecting php with mysql. Mysql server and client is
I'm having a pretty weird problem with PHP and MySQL. I'm doing the following
I'm having some problems connecting to a SOAP Service at https://test.salesforce.com . I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.