...

View Full Version : information regarding THIS



durangod
05-31-2011, 06:22 PM
Hi, i ran accross some code that used "this" in several places but i am unable to find where "this" is set. I did some googling and was unable to find some resources because i am not aware what keyword to search for.

What is "this" ?
Is it a php function?
Javascript function?
Just a standard variable that people use?
a class?

i dont know what it is and if it already has value or if i need to give it value.

link to some documentation or any help appreciated, thanks so much.

bazz
05-31-2011, 06:23 PM
can you post the code or a portion of it, say, from the top down to where 'this' is showing.

bazz

durangod
05-31-2011, 06:32 PM
here is one, but it appears in others as well, the other one looks like some kind of class statment but i cant be sure.

but here is this one(it pulls up an image on mouseover)



onmouseover="this.src='http://www.xxx.com/images/myimage.gif'


but i cant find where this is set because im not sure what im looking for.

Fou-Lu
05-31-2011, 06:33 PM
$this is reserved and cannot be assigned to.
Its a scope resolution for objects. $this resolves to this instance of a class, and PHP doesn't allow variable masking so $this->member and $this->method() must always be used. It is only usable within the scope of an object.
I can't recall which version actually forced this, but I think somewhere between the 5.0 and 5.1 time $this was actually assignable. This was later changed to throw a fatal error. At least I think it was PHP that had done that.


That is javascript, same concept it relies on the dom. this.src refers to this dom object's src property.

Inigoesdr
05-31-2011, 07:13 PM
I think somewhere between the 5.0 and 5.1 time $this was actually assignable. This was later changed to throw a fatal error. At least I think it was PHP that had done that.
Yeah, it was right as/after 5.0 came out. Something like 6 years ago.

durangod
06-01-2011, 07:25 AM
thanks Fou-Lu sorry so late getting back to you, my third party mail client crapped out of me (MS changed its protocal for ssl) and i was upside down getting and sending emails to customers. what a day...

I really appreciate the info. peace dave



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum