Page 1 of 1

Help echo an object

Posted: Mon Oct 05, 2009 4:09 pm
by interminable
Hi, I have a variable $data that contains an object. I can't seem to access any of it's properties though. Kinda new to PHP. When I do a var_dump($data); I get the following output:

Code: Select all

object(stdClass)#2 (1) {
  ["MakePaymentResult"]=>
  object(stdClass)#3 (4) {
    ["isSuccess"]=>
    bool(true)
    ["errorMessage"]=>
    string(0) ""
    ["subType"]=>
    string(25) "PsCreditCardPayment"
    ["psObject"]=>
    object(stdClass)#4 (8) {
      ["isSuccess"]=>
      bool(false)
      ["Type"]=>
      string(4) "Moto"
      ["PaymentId"]=>
      NULL
      ["CustomerId"]=>
      int(714296)
      ["FromAccountId"]=>
      int(306921)
      ["Amount"]=>
      string(3) "2.3"
      ["PaymentDate"]=>
      string(19) "0001-01-01T00:00:00"
      ["InvoiceId"]=>
      NULL
    }
  }
}
but if I then write

Code: Select all

echo $data->$MakePaymentResult->$PaymentDate;
I get nothing.

Re: Help echo an object

Posted: Mon Oct 05, 2009 4:37 pm
by jackpf
Remove last 2 dollar signs. Properties don't need them...unless the property names are variables.

Re: Help echo an object

Posted: Wed Oct 07, 2009 11:58 am
by interminable
Thanks!

Re: Help echo an object

Posted: Wed Oct 07, 2009 1:18 pm
by jackpf
:)