Jump to content

[SOLVED] n00b queastion, what does -> mean?


Cobby

Recommended Posts

In a class you have variable and functions. By calling $this->[function or var(without $)] inside a class, it will call the var or func that is defined in that class.

 

Use [any class name]->[func or var] in general. So replace $this by a class var (= $classvar = new yourclassname;) to call a func or var from another class. Can be in or outside a class.

 

FD

Oh ok,

 

So, just for my ease, I will compare it to a URL.

 

'$this->index' would be like http://localhost/index

and

'url->index' would be like http://53.156.23.4/index  (just a random IP)

 

Well thats how I understand it anyway, is that right? Sorry for the silly metaphor :P

 

Cheers,

Cobby

class test{

 

public $_x;

 

public function func1(){

echo $this->func2();

}

 

public function func2(){

return $this->_x = 3;

}

 

}

 

$f = new test();

$f->func1(); // echo 3

echo $f->func2(); //echo 3 as well

 

-> basically means use. so '$this' means this object. so $this->_x = 3; means set this ojbect's property _x to 3. and $this->func2(); means call method func2() inside of this object. its a pretty simple concept once you work with it for a while

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.