| $this syntax [message #2860] |
Tue, 20 October 2009 11:21  |
jmangin Messages: 4 Registered: September 2008 Location: Maryland |
Shiny and New |
|
|
I've inherited some code that I need to adapt for another purpose. There's a syntax using $this with which I am not familiar. I've seen it before, but I never been taught that style of coding.
e.g.:
function getError($name) {
if($this->isError($name)) {
return $this->errors[$name];
} else {
return false;
}
}
I tried to google "$this", but I can't find it because the search engine ignores the dollar sign and I get every post with the word "this" in it!
So, what is the function of $this? What is the type of syntax called, so I can find the documentation and read more about it.
Thanks,
Julie
|
|
|
| Re: $this syntax [message #2861 is a reply to message #2860 ] |
Wed, 21 October 2009 06:42   |
|
Julie,
This is Object Oriented Programming - you should be able to find some introductory tutorials showing how "$this" is used. Basically $this is an object and the arrow notation -> shows that something is a property of that object. A property is just a variable but it belongs to an object.
So instead of setting $error = 'gone wrong' and returning $error, you set $this->error = 'message of failure' and then you can get that value back again from that object.
Hope that makes some sense - find a tutorial, have a read, and post again if you have any questions, we're always happy to help!
Lorna
Lorna Mitchell (online at http://www.lornajane.net)
|
|
|
|
|
|