Help echo an object

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
interminable
Forum Newbie
Posts: 8
Joined: Thu Oct 01, 2009 4:22 pm

Help echo an object

Post 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.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Help echo an object

Post by jackpf »

Remove last 2 dollar signs. Properties don't need them...unless the property names are variables.
interminable
Forum Newbie
Posts: 8
Joined: Thu Oct 01, 2009 4:22 pm

Re: Help echo an object

Post by interminable »

Thanks!
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Help echo an object

Post by jackpf »

:)
Post Reply