Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question

Status
Not open for further replies.

neilmurray

Technical User
Jan 18, 2005
32
GB
Hi, where can I find info on what $this-> does.
Tried checking th ePHP manual but no Joy.

Thanks,

Neil.
 
I come from a VB background, so encountered the same problem.

In VB you would create a class like this: -

Code:
Public intLength as integer
Public intHeight as integer

public function Area() as integer
   Area=intLength*intHeight  
End function

In VB, if you are within a function of a class and want to reference a class variables within the same class, then you would just invoke the variable name ([tt][blue]Area=intLength*intHeight[/blue][/tt]).

However in PHP, you need to use different syntax: -

Code:
var $Length;
var $Height;

function Area() {
  return $this->Length*$this->Height;
}

In PHP syntax, the class level variable will lose its [tt][blue]$[/blue][/tt] and be post-fixed instead by [tt][blue]$this->[/blue][/tt]. This also holds true when referencing any function of a class externally.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top