0

I'm new to PHP and I really like the concept behind it. Would you be kind enough to explain to me how a line like this would be read?

if ($ThisOutput->result == "success")

In other words, what does that line above mean? How can I understand it?

Thanks!

========

Wow! Thank you to all who have answered! I totally understand this now! :-) I wish I could choose all three of you as the accepted answer, but I can only choose one. Good job ya'll!

Jaime
  • 21
  • 6
  • 2
    If the `result` property of `$ThisOutput` equals `"success"`, then ... – p.s.w.g Aug 22 '14 at 23:06
  • See http://php.net/manual/en/language.oop5.php for an explanation of how classes and objects work in PHP. – developerwjk Aug 22 '14 at 23:08
  • 1
    Explaining the syntax constructs from a single line excerpt is not going to teach you much. It's vastly irrelevant without context even. Read through the PHP manual or a book rather. For the syntax: [Reference - What does this symbol mean in PHP?](http://stackoverflow.com/q/3737139) – mario Aug 22 '14 at 23:08
  • Thank you for the links. I'll definitely be up studying this. :-) – Jaime Aug 23 '14 at 00:05

2 Answers2

1

In php, variables are denoted by a $ prefix. Therefore, $ThisOutput is a variable.

There are several types of variables. For variables of type stdClass (objects) their properties can be accesed with the -> operator.

Your code is evaluating if the property 'result' for the object $ThisOutput has a value equal to the string "success".

An if construct will execute a further command if the argument evaluates to true. So in this case, if $ThisOutput->result is "success" something will be executed, and it won't in any other case.

ffflabs
  • 17,166
  • 5
  • 51
  • 77
0

The -> is used to access variable of functions of php objects.

The exact interpretation of the example depends on the type of object represented by $ThisOutput.

If $ThisOutput is a class, then result would be a member variable of the class. So in that case the line would mean "compare the variable named 'result' in the class $ThisOutput with the string 'success'.

fsmith
  • 1